Advertisement
Guest User

Untitled

a guest
Apr 14th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #assuming we have already on mongo terminal
  2.  
  3. // this will resulting no row
  4. > db.users.find({'email':'marjuqi@gmail.com'}).pretty()
  5.  
  6. // copying Greg's data and store it into temp variable 'marjuqi'
  7. > marjuqi = db.users.findOne({'email':'greg@gmail.com'})
  8.  
  9. // generate new unique ID for 'marjuqi' data
  10. > marjuqi._id = new ObjectId()
  11.  
  12. // update some specific personal info for 'marjuqi' data
  13. > marjuqi.name = 'Marjuqi'
  14. > marjuqi.email = 'marjuqi@gmail.com'
  15.  
  16. // insert it into document
  17. > db.users.insert(marjuqi)
  18.  
  19. // if needed, update/set another field
  20. > db.users.update({'name':'Marjuqi'}, {$set:{'gender':'male'}})
  21.  
  22. // this will resulting one row
  23. > db.users.find({'email':'marjuqi@gmail.com'}).pretty()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement