MongoDB is an alternative to conventional SQL databases. It is one of the most popular NoSQL databases and it is primarly used because of performance, scalability and ease-of-use.

It is especially easy to use with JavaScript!

Terminology - MongoDB vs SQL

Creating and Seeding Collections

Explicit Creation

If the collection doesn’t exist, Mongo will automatically create it with the Insert data. But if you want to create an empty collection, you can do:

db.createCollection( "collectionName", { ...[options] } );

Inserting data

You can insertOne or insertMany data in a collection. Check it out:

db.insertOne({ name: 'Johnny', age: undefined });
db.insertMany([{ name: 'Carlos', age: 11 }, { name: 'Amy', age: 23 }]);

Querying Collections

Deleting Documents

Work similarly to insertOne and insertMany:

deleteOne()

db.inventory.deleteOne({ quantity: 100 }); // Delete first document with quantity 100
db.inventory.deleteOne({ _id: "12ajg23" }); // Delete document with _id = 12ajg23

deleteMany()

db.inventory.deleteMany({ price: { $gt: 100 } }); // Delete every with price greater than 100
db.inventory.deleteMany({}); // Delete every document in collection