MongoDB examples of query operations

This page provides examples of query operations using MongoDB

If you are already connected to MongoDB, you can check the version by using the db.version() method

db.version()

You can see all the databases using the “show” command:

show dbs

Create Database

The command will create a new database if it doesn’t exist, otherwise it will return the existing database.

The database you created (company_db) is not currently in the list. In order to display the database, you will need to insert at least one document into it.

The document name will be “clients”:

db.clients.insert({"name":"client name"})

db.getCollection("clients").find({})

Find By some field
db.getCollection("collection_name").find({ "customer_account": { "$in": [ "1001002003" ] } })
check for null or empty
db.getCollection("collection_name").find({ "product_item": { "$in": [ "",null  ] } })