Skip to content

Instantly share code, notes, and snippets.

@jserrao
Created March 10, 2020 18:46
Show Gist options
  • Save jserrao/56804e98ee60ce3c2efcb410981f7559 to your computer and use it in GitHub Desktop.
Save jserrao/56804e98ee60ce3c2efcb410981f7559 to your computer and use it in GitHub Desktop.
Some MongoDB Test Queries
// Mongo DB commands
db.restaurants.insert({
"name": "Haikan",
"address" : {
"street" : "805 V Street NW",
"zipcode" : 20001
},
"cuisine": "Ramen"
})
/**
* Note the _id syntax
{
"_id" : ObjectId("5d66d59320b95b3438dc6b1e"),
"name" : "Haikan",
"address" : {
"street" : "805 V Street NW",
"zipcode" : 20001
},
"cuisine" : "Ramen"
}
*/
// Something to insert
db.restaurants.insert(
[
{
"name": "Haikan",
"address" : {
"street" : "805 V Street NW",
"zipcode" : 20001
},
"cuisine": "Ramen"
},
{
"name": "Taqueria Habanero",
"address": {
"street": "4710 14th Street NW",
"zipcode": 20010
},
"cuisine": "Mexican"
},
{
"name": "Chicken & Whiskey",
"address": {
"street": "1738 14th Street NW",
"zipcode": 20009
},
"cuisine": "Peruvian"
},
{
"name": "The Coupe",
"address": {
"street": "3415 11th Street NW",
"zipcode": 20010
},
"cuisine": "American"
},
{
"name": "Da Hong Pao",
"address": {
"street": "1409 14th Street NW",
"zipcode": 20005
}
}
]
)
// .find() 'The Coupe' from above
db.restaurants.find(
{
"name": "The Coupe"
}
)
db.restaurants.delete(
{},
{ "do": "whatever"}
)
db.restaurants.insertMany(
{},
{
$set: {
"address.state": "DC"
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment