Mongodb

MongoDB is a scalable, high-performance, open source, document-oriented NoSQL database. It supports a large number of languages and application development platforms. Questions about server administration can be asked on http://dba.stackexchange.com.

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
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
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
59 votes
12 answers
815 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
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
54 votes
22 answers
934 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
66 votes
8 answers
775 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
997 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
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
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
51 votes
15 answers
1.5K views
How to remove a field completely from a MongoDB document?

{ name: 'book', tags: { words: ['abc','123'], lat: 33,

avatar
Keila
0 1 0 9
asked 07 September, 2021
61 votes
6 answers
1.8K views
Add new field to every document in a MongoDB collection

How can I add a new field to every document in an existent collection? I know how to update an existing docum

avatar
Keila
0 1 0 9
asked 07 September, 2021
56 votes
18 answers
1.2K views
How to secure MongoDB with username and password

I want to set up user name & password authentication for my MongoDB instance, so that any remote access wi

avatar
Kristopher
0 1 0 9
asked 07 September, 2021