Skip to content

Instantly share code, notes, and snippets.

@gatesvp
Created March 3, 2011 17:46
Show Gist options
  • Select an option

  • Save gatesvp/853167 to your computer and use it in GitHub Desktop.

Select an option

Save gatesvp/853167 to your computer and use it in GitHub Desktop.
Create a new data field using set
> var d = {
... drives:{
... C:{
... windows:{
... 'explorer':{
... admin:'r+w'
... }
... }
... }
... }
... }
> db.drives.save(d)
> db.drives.findOne()
{
"_id" : ObjectId("4d6fd353af4a000000006c1f"),
"drives" : {
"C" : {
"windows" : {
"explorer" : {
"admin" : "r+w"
}
}
}
}
}
> db.drives.update( { _id : d._id }, { $set : { "drives.C.windows.explorer.admin" : "r" } } )
> db.drives.findOne()
{
"_id" : ObjectId("4d6fd353af4a000000006c1f"),
"drives" : {
"C" : {
"windows" : {
"explorer" : {
"admin" : "r"
}
}
}
}
}
> db.drives.update( { _id : d._id }, { $set : { "drives.C.windows.explorer.guest" : "e" } } )
> db.drives.findOne()
{
"_id" : ObjectId("4d6fd353af4a000000006c1f"),
"drives" : {
"C" : {
"windows" : {
"explorer" : {
"admin" : "r",
"guest" : "e"
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment