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

how to get the return value of findAndModify func in MongoDB with mongoose?

I'm using Node.js+mongoose+MongoDB like this: SomeModelSchema.statics.findAndModify = function (query, sort, doc, options, callback) { return this.collection.findAndModify(query, sort, doc, options, callback); }; SomeModel.findAndModify({}, [],…
NamiW
  • 1,572
  • 4
  • 19
  • 33
7
votes
2 answers

Testing MongooseJs Validations

Does anyone know how to test Mongoose Validations? Example, I have the following Schema (as an example): var UserAccount = new Schema({ user_name : { type: String, required: true, lowercase: true, trim: true, index: { unique: true },…
Donn Felker
  • 9,553
  • 7
  • 48
  • 66
7
votes
1 answer

Increasing one field in a MongoDB collection with Mongoose

I'm trying to increment a value in a collection in my MongoDB database through Mongoose. This is the demo code shown on the Mongoose website: var conditions = { name: 'borne' } , update = { $inc: { visits: 1 }} , options = { multi: true…
Masiar
  • 20,450
  • 31
  • 97
  • 140
7
votes
3 answers

Is MongoDB the right DB for a community site?

I'm creating a community site with Node.JS and Express and almost all express tutorials or examples use MongoDB, so I checked it out. The only DB I used so far is MySQL but I'm not that much familiar with it so it wouldn't bother me to read into…
Xomby
  • 1,247
  • 3
  • 11
  • 10
7
votes
2 answers

Importing a very large record set into MongoDB using nodejs

Before I dive into my question, I wanted to point out that I am doing this partially to get familiarized with node and mongo. I realize there are probably better ways to accomplish my final goal, but what I want to get out of this is a general…
0x6A75616E
  • 4,696
  • 2
  • 33
  • 57
7
votes
1 answer

Mongoose update only updates first document

Okay.. this is odd and annoying, so any help would be GREATLY appreciated. Here's my code: Target.update {location_city: "New York"}, {location_country: "FUDGE!"}, {safe: true}, (err, res) -> console.log "Updating with New York" …
Shamoon
  • 41,293
  • 91
  • 306
  • 570
7
votes
12 answers

throw new MongooseError('Query.prototype.exec() no longer accepts a callback');

throw new MongooseError('Query.prototype.exec() no longer accepts a callback'); ^ MongooseError: Query.prototype.exec() no longer accepts a callback I was trying to register users.
7
votes
1 answer

Mongoose: Suggested database schema

Ok so I am coming from a mySQL background and am now trying to rebuild a site using nodeJS and Mongoose. My old mySQL schema looked something like this (simplified): users user_ID user_name user_email user_password groups group_ID …
wilsonpage
  • 17,341
  • 23
  • 103
  • 147
7
votes
2 answers

Validating multiple Mongoose schema properties?

I'm trying to do the classic thing of making sure a user's username is not the same as their password, in Nodejs/Mongoose. I was thinking it'd be good to use a seperate validation function, but I can't work out how to do it. So far I've used the…
benui
  • 6,440
  • 5
  • 34
  • 49
7
votes
1 answer

node_modules/mongoose/node_modules/mongodb/mongodb.ts34.d.ts:3288:5 - error TS1005: '?' expected

i was trying to build the code in the server but when i m trying to build its showing the below error node_modules/mongoose/node_modules/mongodb/mongodb.ts34.d.ts:3288:5 - error TS1005: '?'…
7
votes
6 answers

How can I solve a "MongoError: E11000 duplicate key error collection" error in Mongo?

I have created a new Mongo collection to a new project, but when I try to create a new user, I get the following error: MongoError: E11000 duplicate key error collection: GestorMedico.users index: username_1 dup key: { username: null } My User…
Victor
  • 253
  • 2
  • 3
  • 12
7
votes
2 answers

How to create Time Series Collection with Mongoose

MongoDB v5.0 introduced a new collection type that is optimized for storing and working with time-series data - Time Series Collections. How can we create a Time Series Collection with Mongoose?
NeNaD
  • 18,172
  • 8
  • 47
  • 89
7
votes
3 answers

How to properly type array of object IDs in mongoose with Typescript

I have a Post Model: const PostSchema = new Schema( { // ... likes: [{ type: Schema.Types.ObjectId, ref: "User" }], // ... } ) export default model("Post", PostSchema) export interface IPost { // ... likes:…
Tiago Brandão
  • 207
  • 3
  • 12
7
votes
6 answers

const err = new MongooseError(message);

I am trying to create a project which allows the user to enter "email", "username" and "Password" to register to the site, When I try to enter a user using the "username", email" and "password" to enter this site, I get the following error: Backend…
Tunde Samson
  • 71
  • 1
  • 1
  • 4
7
votes
3 answers

MongooseError: Query was already executed: Todo.updateOne({ _id: new ObjectId("612df063a8f

I updated mongoose to latest version (6.0.2) and now I'm recieving this error and crush the application whenever .updateOne() is executed. But object update inside the database. My code: async(req,res) => { await Todo.updateOne( {_id :…
Md Tazri
  • 71
  • 1
  • 2