Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #assuming we have already on mongo terminal
- // this will resulting no row
- > db.users.find({'email':'marjuqi@gmail.com'}).pretty()
- // copying Greg's data and store it into temp variable 'marjuqi'
- > marjuqi = db.users.findOne({'email':'greg@gmail.com'})
- // generate new unique ID for 'marjuqi' data
- > marjuqi._id = new ObjectId()
- // update some specific personal info for 'marjuqi' data
- > marjuqi.name = 'Marjuqi'
- > marjuqi.email = 'marjuqi@gmail.com'
- // insert it into document
- > db.users.insert(marjuqi)
- // if needed, update/set another field
- > db.users.update({'name':'Marjuqi'}, {$set:{'gender':'male'}})
- // this will resulting one row
- > db.users.find({'email':'marjuqi@gmail.com'}).pretty()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement