I am looking to use the count in mongo db to count the number of students qualified please see image above
db.docs.find.count(“qualifications”); isnt working
Hello @Marie_Dillane, welcome to the community.
The method you are trying db.docs.find.count(“qualifications”)
doesn’t work. This is because the method you are using is the cursor.count, and it doesn’t take a parameter.
-
db.docs.find().count()
counts all documents in the collection. -
db.docs.find(query).count()
counts all documents in the collection which match the query condition. - db.collection.countDocuments(query) counts documents that match the query in a collection.
You can use the $exists to find documents that have the field qualifications
using one of these queries:
db.docs.find( { qualifications: { $exists: true } } ).count()
db.docs.countDocuments( { qualifications: { $exists: true } } )