Last Updated: September 09, 2019
·
1.199K
· spf13

MongoDB Fundamentals

In the MongoDB shell

$ mongo

Start with an Object

place1 = {
  name : "10gen HQ",
  address : "578 Broadway 7th Floor",
  city : "New York",

  zip : "10011",
  tags : [ "business", "awesome" ]
}

Insert the record

> db.places.insert(place1)

Query for the record

> db.places.findOne({ zip: "10011", tags: "awesome" })

> db.places.find({tags: "business" })

Update the record (atomically)

db.places.update( {name : "10gen HQ"},

 { $push :

 { comments :

 { author : "steve",

 date : 6/26/2012,

 text : "Office hours are great!"

 }

 }

 }

)