Skip to content

Instantly share code, notes, and snippets.

@laurentsab
Last active August 29, 2015 14:19
Show Gist options
  • Save laurentsab/63147f93dbfd8cef3ad5 to your computer and use it in GitHub Desktop.
Save laurentsab/63147f93dbfd8cef3ad5 to your computer and use it in GitHub Desktop.
MongoDB Tips
// Update/Add a new field
Rooms.update({_id: 'XDhybphgkdC7Z4dsn'}, {$set: {user: 'Laurent'}});
// Add array
Rooms.update({_id: 'XDhybphgkdC7Z4dsn'}, {$set: {objects: ['TV', 'Radio', 'Draps'] } } );
// Push a field in an array
Rooms.update({_id: 'XDhybphgkdC7Z4dsn'}, {$push: {objects: ['Lights'] } } );
// Push an array in an array
Rooms.update({_id: 'J5idHne5rrj7Qf7ot'}, {$push: {objects: {$each: [ 'Test1', 'Test2', 'Test3'] } } } );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment