MongoDB profiler output: What is the “command” operation?


The following operations are treated as command operation in MongoDB −

1.count
2.findAndModify
3.aggregate

Following is the example of count in MongoDB −

Let us create a collection with documents −

> db.demo443.insertOne({"Name":"Chris"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5e78d281bbc41e36cc3caeb9")
}
> db.demo443.insertOne({"Name":"Bob"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5e78d285bbc41e36cc3caeba")
}
> db.demo443.insertOne({"Name":"David"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5e78d288bbc41e36cc3caebb")
}

Display all documents from a collection with the help of find() method −

> db.demo443.find();

This will produce the following output −

{ "_id" : ObjectId("5e78d281bbc41e36cc3caeb9"), "Name" : "Chris" }
{ "_id" : ObjectId("5e78d285bbc41e36cc3caeba"), "Name" : "Bob" }
{ "_id" : ObjectId("5e78d288bbc41e36cc3caebb"), "Name" : "David" }

The MongoDB count example is as follows −

> db.demo443.count();

This will produce the following output −

3

Updated on: 06-Apr-2020

139 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements