Questions tagged [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 https://dba.stackexchange.com.

MongoDB is a widely used, general-purpose, document-oriented database with a multitude of features including replication for redundancy and high availability and sharding for horizontal scaling.

The MongoDB Community Edition database server and tools are source-available under Server Side Public License (all versions released after October 16, 2018) or open-source under AGPL v3.0 license (versions released prior to October 16, 2018). Commercial Licenses are also available from MongoDB, Inc.

MongoDB offers a powerful query language, MQL, and provides the Aggregation Framework and Map/Reduce for even more complex queries. MongoDB uses the BSON format for storing data and the MongoDB Wire Protocol for communication between client drivers and the MongoDB server. Officially supported Drivers and Client Libraries are available for most popular programming languages, and there are also Community Supported Drivers which offer alternative implementations and support for further programming languages.

The latest MongoDB server releases can be installed via common packaging systems or downloaded as binary archives from mongodb.com.

The current production release series of MongoDB is 6.0. It is generally recommended to stay current with the latest minor release of a production release series (e.g. 6.0.1) to take advantage of bug fixes and backward-compatible improvements. For more information on the versioning scheme used by the server, see MongoDB Version Numbers.

MongoDB has a GUI called MongoDB Compass, which is a powerful GUI for querying, aggregating, and analyzing your MongoDB data in a visual environment. Compass is free to use and source available and can be run on macOS, Windows, and Linux.

FAQ

MongoDB Community Forums are the official home for community discussion, product/driver announcements, and introductions.

For help with data modeling (schema design), check out the Data Models documentation page, the Building with Patterns blog series, and M320: Data Modeling course at MongoDB University.

For information on MongoDB Security, view the Security section of the MongoDB Manual which includes a MongoDB Security Checklist.

MongoDB, Inc. (the company behind MongoDB) provides archives of many presentations from their events such as conferences and webinars. They also develop a number of related tools and services including MongoDB Cloud Manager, MongoDB Ops Manager, MongoDB Atlas, and MongoDB Compass.

Useful links

Related Tags

Initial Release:

Feb 11, 2009

Latest Production Release Series:

6.0 (July 19, 2022 - Release notes)

Books

Articles

174599 questions
441
votes
20 answers

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 will ask for the user name & password. I tried the tutorial from the MongoDB site and did following: use admin db.addUser('theadmin',…
murvinlai
  • 48,919
  • 52
  • 129
  • 177
425
votes
8 answers

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 appearing in my MongoDB documents. Is it something to do with versioning? How is it used?
Simon Lomax
  • 8,714
  • 8
  • 42
  • 75
422
votes
16 answers

Mongoose: findOneAndUpdate doesn't return updated document

Below is my code var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/test'); var Cat = mongoose.model('Cat', { name: String, age: {type: Number, default: 20}, create: {type: Date, default: Date.now}…
Dreams
  • 8,288
  • 10
  • 45
  • 71
397
votes
13 answers

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 work: db.theColl.find( { _id: ObjectId("4ecbe7f9e8c1c9092c000027") } ) The query returned no results. I found the 4ecbe7f9e8c1c9092c000027 by…
jcollum
  • 43,623
  • 55
  • 191
  • 321
394
votes
27 answers

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({"foo":"BAR"}).count(); 0
Luke Dennis
  • 14,212
  • 17
  • 56
  • 69
380
votes
25 answers

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 collection is: { "_id" : ObjectId("53d9feff55d6b4dd1171dd9e"), "name" : "Swati", "roll" : "80", } I want to retrieve the field…
Shipra Swati
  • 3,999
  • 2
  • 14
  • 7
373
votes
25 answers

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.insert( { type : ['dog', 'cat'] } ); db.things.insert( { egg : ['cat'] } ); db.things.insert( { type : [] } ); db.things.insert( { hello : [] }…
Steve
  • 4,859
  • 5
  • 21
  • 17
371
votes
9 answers

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 with about 20 million records indexed only on a field called 'id'. I wanted to compare speed with MongoDB and I ran a test which would get…
Imran Omar Bukhsh
  • 7,849
  • 12
  • 59
  • 81
358
votes
23 answers

E11000 duplicate key error index in mongodb mongoose

Following is my user schema in user.js model - var userSchema = new mongoose.Schema({ local: { name: { type: String }, email : { type: String, require: true, unique: true }, password: { type: String, require:true }, …
Trialcoder
  • 5,816
  • 9
  • 44
  • 66
356
votes
13 answers

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 how to manage connections: Is it enough using only one MongoDB connection for all requests? Are there any performance issues? If not, can I setup…
Freewind
  • 193,756
  • 157
  • 432
  • 708
355
votes
9 answers

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 like ... // doesn't work ... of course ... model.find({ '_id' : [ '4ed3ede8844f0f351100000c', '4ed3f117a844e0471100000d', …
ezmilhouse
  • 8,933
  • 7
  • 29
  • 38
346
votes
24 answers

How do I remove documents using Node.js Mongoose?

FBFriendModel.find({ id: 333 }, function (err, docs) { docs.remove(); //Remove all the documents that match! }); The above doesn't seem to work. The records are still there. Can someone fix?
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
333
votes
9 answers

Ways to implement data versioning in MongoDB

Can you share your thoughts how would you implement data versioning in MongoDB. (I've asked similar question regarding Cassandra. If you have any thoughts which db is better for that please share) Suppose that I need to version records in an simple…
Piotr Czapla
  • 25,734
  • 24
  • 99
  • 122
333
votes
9 answers

MongoDB SELECT COUNT GROUP BY

I am playing around with MongoDB trying to figure out how to do a simple SELECT province, COUNT(*) FROM contest GROUP BY province But I can't seem to figure it out using the aggregate function. I can do it using some really weird group…
Steven
  • 13,250
  • 33
  • 95
  • 147
332
votes
5 answers

How to search in array of object in mongodb

Suppose the mongodb document(table) 'users' is { _id: 1, name: { first: 'John', last: 'Backus' }, birth: new Date('Dec 03, 1924'), death: new Date('Mar 17, 2007'), contribs: ['Fortran', 'ALGOL', 'Backus-Naur…
vcxz
  • 4,038
  • 4
  • 18
  • 17