Skip to content

Instantly share code, notes, and snippets.

@SarasArya
Created April 29, 2017 09:08
Show Gist options
  • Save SarasArya/ba97d1364a28b52ce5163857861e2b6c to your computer and use it in GitHub Desktop.
Save SarasArya/ba97d1364a28b52ce5163857861e2b6c to your computer and use it in GitHub Desktop.
mongodb commands I find useful, especially when dealing with embedded documents.
//To remove a field from each document. Whenever I introduce a field by mistake
db.example.update({}, {$unset: {words:1}} , {multi: true});
//To search in array of objects in mongodb
db.collection.find( { field1: { $elemMatch: { one: 1 } } } );
//To update array of objects in mongodb console
db.roles.update({"userId" : ObjectId("58a191b8d02dde3638a5a4ee"), "children.requestStatus" : 'Rejected'},{$set : {"children.$.requestStatus" : "Authorized"}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment