MongoDB Tips and Snippets
Rename a field
jsdb.collectionName.updateMany({}, {$rename: {'StudentName': "StudentFirstName"}});Add a new field
db.documents.update(
{},
{$set : {"location":"/blog"}},
{upsert:false,
multi:true}
) db.your_collection.update({}, {$set : {"new_field":null}}, {upsert:false, multi:true})db.your_collection.update({}, {$set : {"new_field":[]}}, {upsert:false, multi:true})Find Documents Missing a Given Field
Remove a Field
Delete a Document
Last updated