Skip to content

Instantly share code, notes, and snippets.

@adkron
Created February 20, 2011 01:09
Show Gist options
  • Save adkron/835572 to your computer and use it in GitHub Desktop.
Save adkron/835572 to your computer and use it in GitHub Desktop.
Remove all of one field from an array of fields in an entire collection
/*
I want to remove all the bool fields(inside the props array) from the following collection.
*/
//Initial state of collection
db.foos.find();
//#=>
{ "_id" : ObjectId("4d60699c768262073556634f"), "props" : [
{
"bool" : true,
"name" : "bob"
},
{
"bool" : false,
"name" : "noah"
}
] }
{ "_id" : ObjectId("4d6069a07682620735566350"), "props" : [
{
"bool" : true,
"name" : "amos"
},
{
"bool" : false,
"name" : "miriam"
}
] }
//Wanted state of collection
db.foos.find();
//#=>
{ "_id" : ObjectId("4d60699c768262073556634f"), "props" : [
{
"name" : "bob"
},
{
"name" : "noah"
}
] }
{ "_id" : ObjectId("4d6069a07682620735566350"), "props" : [
{
"name" : "amos"
},
{
"name" : "miriam"
}
] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment