This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install mongodb --save |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.collectionName.insertMany( | |
[ <document 1> , <document 2>, ... ], | |
{ ordered: false } | |
) | |
// Example | |
db.products.insertMany( [ | |
{ _id: 10, item: "large box", qty: 20 }, | |
{ _id: 11, item: "small box", qty: 55 }, | |
{ _id: 11, item: "medium box", qty: 30 }, | |
{ _id: 12, item: "envelope", qty: 100}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.myCollection.drop() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use databaseName | |
db.dropDatabase() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.collectionName.insertMany( [ <document 1> , <document 2>, ... ]) | |
// example | |
db.patients.insertMany([{ | |
"firstName": "Max", | |
"lastName": "Martinez", | |
"age": 29, | |
"history": [{ | |
"disease": "cold", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creating a collection using lazy mode | |
db.collectionName | |
// Createing a collection using createCollection method | |
db.createCollection() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
show dbs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use dabase_name | |
// Note: If you try to see all database using show dbs you will notice that the database create it won't be list. That is because databese only will show once it have a collection with at least one document. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.collectionName.updateMany({}, {$set: {"canEdit": true}}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.collectionName.updateOne( | |
{ "name" : "Pizza Rat's Pizzaria" }, | |
{ $set: {"_id" : 4, "violations" : 7, "borough" : "Manhattan" } }, | |
); | |
#the first parameter is the filter, it mean that mongo is going to update the collection that match with this creteria |