Created
November 29, 2015 06:08
-
-
Save AlifArnado/e26250b8d19d95633dc2 to your computer and use it in GitHub Desktop.
menambahkan data didalam subquery dengan MongoDB
This file contains 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.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