Mongoose.js: remove collection or DB
This can now be done in Mongoose. MyModel.collection.drop(); Hat tip: https://github.com/Automattic/mongoose/issues/4511
This can now be done in Mongoose. MyModel.collection.drop(); Hat tip: https://github.com/Automattic/mongoose/issues/4511
As of Mongoose 4.0 you can run validators on update() and findOneAndUpdate() using the new flag runValidators: true. Mongoose 4.0 introduces an option to run validators on update() and findOneAndUpdate() calls. Turning this option on will run validators for all fields that your update() call tries to $set or $unset. For example, given OP’s Schema: … Read more
In the latest mongoose (3.8.1 at the time of writing), you do two things differently: (1) you have to pass single argument to sort(), which must be an array of constraints or just one constraint, and (2) execFind() is gone, and replaced with exec() instead. Therefore, with the mongoose 3.8.1 you’d do this: var q … Read more
You can define a unique compound index using an index call on your schema: person.index({ firstName: 1, lastName: 1}, { unique: true });