The Mongoose buffer timing out occurred when the model was being used in a linked project

The task:

I developed a ShoppingCard project to test TypeScript references.

The issue:

When models are directly included in the main project, the MongoDB connection works successfully.

https://github.com/pzoli/shoppingcard-api

Tested at http://localhost:8080/api-docs/

However, when I move models to a referenced project, I encounter the following error:

MongooseError: Operation amounttypes.find() buffering timed out after 10000ms

https://github.com/pzoli/shoppingcard-api/tree/ref-models

https://github.com/pzoli/shoppingcard-models

The configuration in tsconfig.json for shoppingcard-api is:

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "outDir": "./build",
    "strict": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  },
  "references": [{ "path": "../shoppingcard-models" }],
}

The tsconfig.json setup for shoppingcard-models is as follows:

{
  "compilerOptions": {
    "sourceMap": true,
    "target": "esnext",
    "module": "CommonJS",
    "outDir": "./dist",
    "baseUrl": "./src",
    "alwaysStrict": true,
    "noImplicitAny": true,
    "importHelpers": true,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "esModuleInterop": true,
    "emitDecoratorMetadata": true,
    "strictPropertyInitialization": false,
    "skipLibCheck": true,
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "types": [
      "node"
   ],
   "rootDir": "./src",
   "typeRoots": [
      "node_modules/@types"
    ],
    "composite": true
  },
  "include": [
      "src/**/*.ts"
  ],
  "exclude": [
      "node_modules",
      "dist"
  ]
}

Here is the package.json file for shoppingcard-api:

{
  "name": "quizserver",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "start": "node build/app.js",
    "build": "tsc",
    "dev": "nodemon"
  },
  "nodemonConfig": {
    "watch": [
       "src"
    ],
    "ext": "ts",
    "exec": "ts-node src/app.ts"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
     "dotenv": "^16.0.3",
     "express": "^4.18.2",
     "joi": "^17.9.1",
     "mongoose": "^7.0.4",
     "swagger-ui-express": "^4.6.2",
     "typescript": "^5.0.4",
     "yaml": "^2.2.1"
  },
  "devDependencies": {
     "@types/express": "^4.17.17",
     "@types/joi": "^17.2.3",
     "@types/node": "^18.15.12",
     "@types/swagger-ui-express": "^4.1.3",
     "nodemon": "^2.0.22",
     "ts-node": "^10.9.1"
  }
}

And here is the package.json content for shoppingcard-models:

{
  "name": "backend-models",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "tsc"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
     "joi": "^17.9.2",
     "mongoose": "^7.2.2",
     "tslib": "^2.5.3"
  }
}

Your assistance in finding the reason why Mongoose is not working is greatly appreciated.

Answer №1

I received this response on the Mongoose GitHub issue tracker:

It seems that your secondary project may have a separate version of the Mongoose module installed, causing the model() function to export a model connected to the incorrect version of Mongoose.

To resolve this, consider having shoppingcard-models export schemas rather than models, and then use the model() function in your primary project instead.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering difficulties importing a component from a library into my Nx Expo React Native application

Having an issue with my Nx monorepo which contains an Expo React Native app and various libraries. The problem arises when trying to import a component from a library within the application, resulting in Error: Cannot resolve @monorepo/account-manager Wi ...

What are the necessary peer dependencies for Angular-compatible projects?

In the process of integrating RxJS as a peer dependency for my Angular 6 project, I encountered an interesting declaration method. Take, for instance, angular/flex-layout, which declares its RxJS dependency in this manner: "requiredAngularVersion": ">= ...

Run the function solely once the asynchronous function has been executed

I need function F1() to wait for function F2() to fully execute and receive the response from a REST call in order to set some data. Here is the code I attempted to use: this.F1().subscribe(result => { this.F2(result); }) F1() { retur ...

"Facing a challenge with Angular 2 where an HTTP request is being triggered twice

After thorough research on Stack Overflow, I can confidently say that the issue is not with my code. However, my REST APIs are being called twice. Here is a snippet of my code: Component: export class Component { constructor(private _nServ ...

node-ts displays an error message stating, "Unable to locate the name '__DEV__' (TS2304)."

I recently inserted __DEBUG__ into a TypeScript file within my NodeJS project. Interestingly, in VSCode, no error is displayed. However, upon running the project, I encounter an immediate error: error TS2304: Cannot find name '__DEBUG__'. I att ...

Extract specific elements from an array using Mongoose's $slice operator while still maintaining the

Currently, my task is to retrieve the total number of items in my News object and return a portion of those items as objects. While I have successfully implemented the $slice operator in my query, I am struggling to determine the original array size of the ...

Encountering an error: Reading an undefined property - NodeJS, Express, and Mongoose

These are the two functions I have: exports.list = function (req, res){ Material.find(function(err, materials) { res.render('materials/list', {title: 'Pagina Materiali', materials: materials}); }); } exports.modify = function (req ...

What is the best way to retrieve the oldest entry from a MongoDB group while staying within the group's context

I've got a set of records and I'm trying to retrieve a unique record for each row with the unique record being the group. Here's the query: db.collection.aggregate([ { $match : { userId: 16, userListId : ObjectId(&apos ...

The 'setState' property is not found on the 'Window' type

I am encountering an issue with the code snippet in my index.tsx file let state = {}; window.setState = (changes: any) => { state = Object.assign({}, state, changes); ReactDOM.render(<App {...state} />, document.getElementById("root")); ...

Discover upcoming files based on the date of the included subdocuments

If I have MongoDB Event documents with multiple sessions on different dates, it can be represented like this: db.events.insert([ { _id: '5be9860fcb16d525543cafe1', name: 'Past', host: '5be9860fcb16d525543daff1', ...

What is the proper way to utilize setTimeout in TypeScript?

Let's take a look at an example of how to use setTimeout in Angular and TypeScript: let timer: number = setTimeout(() => { }, 2000); However, upon compilation, you may encounter the following error message: Error TS2322: Type 'Timeout' ...

Creating a time-series data bucket pattern in MongoDB using Python and PyMongo

I am looking to create time-based buckets, specifically for every hour or more if necessary. I came across the bucket pattern here https://docs.mongodb.com/manual/tutorial/model-time-data/#example but I am unsure of what Python pymongo code to use. My data ...

Intellisense fails to function properly after attempting to import a custom npm package

I've encountered an issue with a custom npm package that I created using storybook. The components function properly in other projects when imported, but the intellisense feature is not working as expected. Interestingly, when I import the same compon ...

Issue: Combination of email and password is invalid when using Node.js and MongoDB

While trying to log in as an admin, I have defined the login credentials both in MongoDB and in the .env file. Below is the code snippet that seems to be causing a problem: const Admin = require('../models/admin'); const Voters = require('.. ...

Mongoose Raises an Error When a Nonexistent Key is Detected

I am currently working on a code where I update my schema object with the request body. I have validation rules set up on the schema, but I'm facing an issue. I want the schema to throw an error when there is a non-existing field in the request body. ...

Getting around using Material-UI Icons

Is it possible to utilize a Material-UI Icon for navigation using React Router Dom? I attempted the following approach without success: <NavigateBeforeIcon path="/vehicles"></NavigateBeforeIcon> With buttons, I am able to use component={Link ...

Is there a way to incorporate a dropdown feature into a search bar using Ant Design?

I'm currently working on a project that requires me to incorporate two drop-down menus inside the search box. Despite following the guidelines provided in the documentation (https://ant.design/components/input), I encountered a problem when trying to ...

Monitoring Local Host with MongoDB Service

Are there any MongoDB server performance monitoring tools available for running on a local host or machine? My main concern is privacy, as I am hesitant to use third-party hosting tools such as the MongoDB Monitoring Service. ...

Typescript typings for child model/collection structures

I have encountered an issue while trying to implement a Model/Collection pattern with various typings. Both the Model and Collection classes have a method called serialize(). When this method is called on the Collection, it serializes all the Model(s) with ...

Is it possible to use the HostListener in Angular 7 to detect any scroll event occurring on a specific element within a webpage?

I am developing a breadcrumb bar component in Angular 7 that should dynamically hide and show based on user scrolling behavior. To achieve this, I created a directive to track the scroll position of the container element. While my code for capturing the s ...