Skip to content

Instantly share code, notes, and snippets.

@AlifArnado
Created November 29, 2015 06:08
Show Gist options
  • Save AlifArnado/e26250b8d19d95633dc2 to your computer and use it in GitHub Desktop.
Save AlifArnado/e26250b8d19d95633dc2 to your computer and use it in GitHub Desktop.
menambahkan data didalam subquery dengan MongoDB
> db.investori.find().pretty();
{
"_id" : ObjectId("565a935647bae189db6b9962"),
"item" : "ABC1",
"detail" : {
"model" : "14Q3",
"manufacture" : "XYZ Company"
},
"stok" : [
{
"size" : "S",
"qty" : 10
},
{
"size" : "M",
"qty" : 20
}
]
}
> db.investori.update({"item": "ABC1"}, {$addToSet: { "stok": {"size": "XL", "qty":30}}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.investori.find().pretty();
{
"_id" : ObjectId("565a935647bae189db6b9962"),
"item" : "ABC1",
"detail" : {
"model" : "14Q3",
"manufacture" : "XYZ Company"
},
"stok" : [
{
"size" : "S",
"qty" : 10
},
{
"size" : "M",
"qty" : 20
},
{
"size" : "XL",
"qty" : 30
}
]
}
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment