Tag: mongoose

49 votes
6 answers
2.5K views
Stop Mongoose from creating _id property for sub-document array items

If you have subdocument arrays, Mongoose automatically creates ids for each one. Example: { _id: "mainId"

avatar
Corrin
0 1 0 9
asked 07 September, 2021
54 votes
22 answers
607 views
Avoid "current URL string parser is deprecated" warning by setting useNewUrlParser to true

I have a database wrapper class that establishes a connection to some MongoDB instance: async connect(connect

avatar
Jeff
0 1 0 9
asked 07 September, 2021
55 votes
30 answers
982 views
How to paginate with Mongoose in Node.js?

I am writing a webapp with Node.js and mongoose. How can I paginate the results I get from a .find() call? I w

avatar
Hilario
0 1 0 9
asked 07 September, 2021
62 votes
30 answers
3K views
E11000 duplicate key error index in mongodb mongoose

Following is my user schema in user.js model - var userSchema = new mongoose.Schema({ local: { na

avatar
Don
0 1 0 9
asked 07 September, 2021
51 votes
8 answers
1.5K views
mongodb/mongoose findMany - find all documents with IDs listed in array

I have an array of _ids and I want to get all docs accordingly, what's the best way to do it ? Something

avatar
Royal
0 1 0 9
asked 07 September, 2021
51 votes
11 answers
423 views
Mongoose: findOneAndUpdate doesn't return updated document

Below is my code var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/tes

avatar
Hildegard
0 1 0 9
asked 07 September, 2021
57 votes
7 answers
448 views
What is the "__v" field in Mongoose

I'm using Mongoose version 3 with MongoDB version 2.2. I've noticed a __v field has started appearin

avatar
Georgie
0 1 0 9
asked 07 September, 2021
62 votes
23 answers
2.8K views
How do I update/upsert a document in Mongoose?

Perhaps it's the time, perhaps it's me drowning in sparse documentation and not being able to wrap m

avatar
Rufus
0 1 0 9
asked 07 September, 2021
54 votes
12 answers
2.4K views
Find document with array that contains a specific value

If I have this schema... person = { name : String, favoriteFoods : Array } ... where the favoriteFo

avatar
Frederick
0 1 0 9
asked 07 September, 2021
63 votes
13 answers
1.3K views
Find MongoDB records where array field is not empty

All of my records have a field called "pictures". This field is an array of strings. I now want the newest 10

avatar
Roger
0 1 0 9
asked 07 September, 2021