Tag: mongodb

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
613 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
986 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
22 answers
3K views
How to select a single field for all documents in a MongoDB collection?

In my MongoDB, I have a student collection with 10 records having fields name and roll. One record of this col

avatar
Serina
0 1 0 9
asked 07 September, 2021
57 votes
7 answers
3.1K views
How to print out more than 20 items (documents) in MongoDB's shell?

db.foo.find().limit(300) won't do it. It still prints out only 20 documents. db.foo.find().toArray() d

avatar
Serina
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
48 votes
30 answers
439 views
Render basic HTML view?

I have a basic node.js app that I am trying to get off the ground using Express framework. I have a views fol

avatar
Clarice
0 1 0 9
asked 07 September, 2021
47 votes
8 answers
2.7K views
Ways to implement data versioning in MongoDB

Can you share your thoughts how would you implement data versioning in MongoDB. (I've asked similar quest

avatar
Chaya
0 1 0 9
asked 07 September, 2021
56 votes
23 answers
2.1K views
How do I remove documents using Node.js Mongoose?

FBFriendModel.find({ id: 333 }, function (err, docs) { docs.remove(); //Remove all the documents that

avatar
Majorie
0 1 0 9
asked 07 September, 2021
59 votes
12 answers
820 views
How do I manage MongoDB connections in a Node.js web application?

I'm using the node-mongodb-native driver with MongoDB to write a website. I have some questions about ho

avatar
Forrest
0 1 0 9
asked 07 September, 2021
57 votes
12 answers
3K views
How do I search for an object by its ObjectId in the mongo console?

I've found this question answered for C# and Perl, but not in the native interface. I thought this would

avatar
Nidia
0 1 0 9
asked 07 September, 2021
51 votes
11 answers
427 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
54 votes
22 answers
939 views
Get names of all keys in the collection

I'd like to get the names of all the keys in a MongoDB collection. For example, from this: db.things.in

avatar
Joseph
0 1 0 9
asked 07 September, 2021
57 votes
24 answers
2.8K views
MongoDB: Is it possible to make a case-insensitive query?

Example: > db.stuff.save({"foo":"bar"}); > db.stuff.find({"foo":"bar"}).count(); 1 > db.stuff.find(

avatar
Thurman
0 1 0 9
asked 07 September, 2021
56 votes
7 answers
2.3K views
"continue" in cursor.forEach()

I'm building an app using meteor.js and MongoDB and I have a question about cursor.forEach(). I want to c

avatar
Suzan
0 1 0 9
asked 07 September, 2021
66 votes
8 answers
779 views
MySQL vs MongoDB 1000 reads

I have been very excited about MongoDb and have been testing it lately. I had a table called posts in MySQL wi

avatar
Jesenia
0 1 0 9
asked 07 September, 2021
54 votes
28 answers
1K views
Random record from MongoDB

I am looking to get a random record from a huge collection (100 million records). What is the fastest and most

avatar
Karolyn
0 1 0 9
asked 07 September, 2021
57 votes
7 answers
453 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
59 votes
30 answers
1.8K views
How to export all collections in MongoDB?

I want to export all collections in MongoDB by the command: mongoexport -d dbname -o Mongo.json The resul

avatar
Jefferey
0 1 0 9
asked 07 September, 2021