Skip to content

Latest commit

 

History

History
29 lines (24 loc) · 617 Bytes

mongodb.md

File metadata and controls

29 lines (24 loc) · 617 Bytes

MongoDB

Sort the results

db.collection.find().sort( { age: -1 } )

Show only specific fields

db.collection.find({}, { name: true, _id: false } )

Finding documents using operators

db.collection.find({ count: { $gt: 10 } })
db.collection.find({ count: { $lte: 10 } }) 
db.collection.find({ type: { $exists: true } }) 
db.collection.find({ name: { $regex: '^U' } }) 

Update document

db.collection.update({ name: 'Something'}, { $set : { operator: 'Starfleet', class: 'Prometheus' } })

Insert document

db.collection.insert({ name: 'card', age: 21 })