Skip to content

CRUD operations

Nikolas Bompetsis edited this page May 30, 2020 · 2 revisions

Connect to mongodb cli

> mongodb master ✗ mongo -u admin -p admin --authenticationDatabase admin

> use project

Select Documents in a Collection

  • Select all documents
> db.stackoverflow.find({})
  • Select documents from Country Greece
> db.stackoverflow.find({Country: "Greece"})

or case sensitive
> db.stackoverflow.find( {Country: /^GREECE$/i})
  • Select documents from many Countries Greece
> db.stackoverflow.find( {Country: {$in: ["Greece", "Thailand"]}})
  • Select documents from Country Greece and age greater than 30
> db.stackoverflow.find({Country: "Greece", Age: {$gt: 30 }})
  • Select documents and return only specific field from query
> db.stackoverflow.find({Country: "Greece", Age: {$gt: 30 }}, {Age:1 , Country:1 , _id:0})
Clone this wiki locally