0

How to display the total number of records and actual records in a single query in MongoDB?

> db.Test.count();
6
> db.Test.find();
{ "_id" : 112, "User_Name" : "Sachin Tendulkar", "Date_Of_Join" : ISODate("2018-03-04T00:00:00Z"), "Education" : [ "10th", "Ph.D" ], "Hobby" : [ "Cricket" ], "Job_Category" : [ "Coach" ], "Gender" : "Male", "Salary" : "$90000", "new" : 1, "IND_Salary" : 500 }
{ "_id" : ObjectId("5c4882b5a28e9a1617ea4fe1"), "Salary" : 5000, "new" : 1, "IND_Salary" : 500 }
{ "_id" : ObjectId("5c4882b9a28e9a1617ea4fe2"), "Salary" : 500, "new" : 1, "IND_Salary" : 500 }
{ "_id" : ObjectId("5c4973694d9171f5a5425760"), "Salary" : 6000, "new" : 1, "IND_Salary" : 500 }
{ "_id" : ObjectId("5c4973714d9171f5a5425761"), "Salary" : 4000, "new" : 1, "IND_Salary" : 500 }
{ "_id" : ObjectId("5c49737b4d9171f5a5425762"), "Salary" : 4500, "new" : 1, "IND_Salary" : 500 }

Here I have only 6 records but if I have end nuber of records while display how can we identify the total amount of documents? Should I scroll to last records for counting? Or is there any better way?

Daniel W.
  • 31,164
  • 13
  • 93
  • 151
Neo The Hacker
  • 67
  • 1
  • 10
  • What do you mean by total and actual records? I see 6 records, nothing else. – Daniel W. Jan 24 '19 at 12:23
  • Refer to this - https://stackoverflow.com/questions/20348093/mongodb-aggregation-how-to-get-total-records-count – Mo A Jan 24 '19 at 13:01
  • .count() is method work with find you can use it to return the number of document. db.Test.find(conditions).count() – Ashok Jan 24 '19 at 13:08
  • Total means no. which is in integer and actual records meaning the records come in json i want both at a time not with different two queries. – Neo The Hacker Jan 27 '19 at 10:33

0 Answers0