How to remove a field from a collection in mongoDB?
How to remove a field from a collection in mongoDB?
By this query you can remove a field from whole collection in mongoDB
db.colleciton.update(
// where query like: where active="yes"
{
"active" : "yes"
},
// will remove Name field from current collection
{
$unset: {"Name":""}
},
// options
{
"multi" : true // update all document
}
);
or you can copy and paste this code above code is with comment that how mongoDB query works
db.colleciton.update(
{
"active" : "yes"
},
{
$unset: {"Name":""}
},
{
"multi" : true
}
);
By this query you can remove a field from whole collection in mongoDB
db.colleciton.update(
// where query like: where active="yes"
{
"active" : "yes"
},
// will remove Name field from current collection
{
$unset: {"Name":""}
},
// options
{
"multi" : true // update all document
}
);
or you can copy and paste this code above code is with comment that how mongoDB query works
db.colleciton.update(
{
"active" : "yes"
},
{
$unset: {"Name":""}
},
{
"multi" : true
}
);
Comments
Post a Comment