Questions tagged [mongoose]

Mongoose is a MongoDB object modeling tool, or ODM (Object Document Mapper), written in JavaScript and designed to work in an asynchronous environment.

Mongoose is a MongoDB object modeling tool, or ODM (Object Document Mapper), written in JavaScript and designed to work in an asynchronous environment.

Documentation

Related links

To open a bug or feature request, visit: https://github.com/Automattic/mongoose/issues

For Mongoose, an embeddable web server written in C, use .

Installations

npm install --save mongoose
46587 questions
7
votes
2 answers

Mongoose connection error when using db name in connection string

When I try to connect to Mongo instance using this connection string mongodb://root:password@localhost:27017/ everything works, however, when I try to specify the database name in the connection string i.e …
eugenekgn
  • 1,652
  • 2
  • 17
  • 38
7
votes
1 answer

Cannot test mongo aggregation MongoError: Unrecognized pipeline stage name: '$set'

Im using mongo aggregation with mongoose. It works fine, but fails when run in jest. I get the error: MongoError: Unrecognized pipeline stage name: '$set' when using $set inside an aggregation $set: { isUsersContent: { …
Nidor
  • 85
  • 1
  • 5
7
votes
3 answers

mongoose - select specific fields in Model.create

const generatedEvent = await Event.create(req.body); res.send(generatedEvent); I am getting some data from the request body and I can generate a new Event. And I'm returning the event to client when it has generated. But I don't want to return…
ahmetbcakici
  • 363
  • 6
  • 17
7
votes
2 answers

Find with array of IDs in mongoose

I make an API with Express.js and mongoose. I need to find users whose id is contained in an array. // the array of ids const followedIds = follow.map((f) => f.followed); console.log(followedIds); // return [ '5ebaf673991fc602045ed47f',…
apinot
  • 85
  • 1
  • 1
  • 5
7
votes
1 answer

mongoDB returning with $numberDecimal in the response of a query

Below is my mongoose schema const mongoose = require('mongoose'); const AccountingCostsSchema = mongoose.Schema( { // other properties goes here accountCosts: { type: mongoose.Decimal128, set: (v) => …
The JOKER
  • 453
  • 8
  • 21
7
votes
2 answers

Use Mongoose-Transactions over multiple databases

I am creating a Node.js API consisting of multiple Microservices. Each Microservice is responsible for one or more features of my application. However, my data is structured into multiple databases which each have multiple collections. Now I need…
linus_hologram
  • 1,595
  • 13
  • 38
7
votes
2 answers

Redis won't retrieve data from cache

I'm following a tutorial and I created a cache.js file that takes the mongoose query and JSON.stringifies it into the key for the values being returned by that query. The goal is to cache that and then append .cache() inside app.js where the…
user6680
  • 79
  • 6
  • 34
  • 78
7
votes
2 answers

NodeJs :- Getting "missing credentials" error while using local passport

I was trying to implement a functionality where a user can reset a password. I have tried the below code and while I am not getting any error, its not updating the password. The password is the same ie the old password. my User model file is as…
SemperFi
  • 190
  • 2
  • 14
7
votes
2 answers

The options [useFindAndModify] is not supported

Using mongodb-4.0.10 and mongoose-5.2.10 Added useFindAndModify: false to the mongoose configuration to avoid warnings like: DeprecationWarning: Mongoose: findOneAndUpdate() and findOneAndDelete() without the useFindAndModify option set to …
Bilal Khan
  • 279
  • 1
  • 3
  • 14
7
votes
6 answers

Why are mongodb queries to a localhost instance of mongo so much faster than to a cloud instance?

I'm using this code to run the tests outlined in this blog post. (For posterity, relevant code pasted at the bottom). What I've found is that if I run these experiments with a local instance of Mongo (in my case, using docker) docker run -d -p…
dwjohnston
  • 11,163
  • 32
  • 99
  • 194
7
votes
1 answer

How to mock Mongoose 'find()' function in Jest?

I have a service: export default class WorldService { constructor(worldModel) { this.worldModel = worldModel; } async getWorlds() { let resData = {}; await this.worldModel.find({}, (err, worlds) => { resData = worlds; …
Ugnius Malūkas
  • 2,649
  • 7
  • 29
  • 42
7
votes
5 answers

First Name and Last Name Combine search in mongoDB

I have store two field FirstName and LastName stored in MongoDB.from Frontend, I am receiving a string containing both first name and last name separated by space I need a find query which searches both first name & last name combined. here is eg.…
Hemant Rajpoot
  • 683
  • 1
  • 11
  • 29
7
votes
2 answers

MongoDB search and pagination Aggregation Performance issue

I'm new in node js and MongoDB. I'm working on MongoDB search and pagination which is working good, but I have an issue with performance. it is taking too much time in counting and search records. if I use small word to search then it works faster,…
JON
  • 965
  • 2
  • 10
  • 28
7
votes
1 answer

Mongodb conditional sort

I want to add a field to the sort clause, for only those documents that created one day ago. Suppose in my collection mycollection my documents have a field publishDate, and some other fields, and following is my…
jones
  • 1,423
  • 3
  • 35
  • 76
7
votes
2 answers

Set sort order for mongoose document

I have a mongoose schema: models/profile.js var mongoose = require("mongoose"); var passportLocalMongoose = require("passport-local-mongoose"); var profileSchema = new mongoose.Schema({ username: String, complete: { type: Boolean,…
fugu
  • 6,417
  • 5
  • 40
  • 75
1 2 3
99
100