1
cursor2 = db.BrandScoreHistoryUpdateFinal.find(
        {"UserOid" :ObjectId("55d6e7c0f0639509b4c7a83b")}).count()

It should return the count of userid for that particular value but its poping out the error as

Name Error: name objectid is not defined.

when I tried to use :

ObjectId("55d6e7c0f0639509b4c7a83b").toString()
cursor2 = db.BrandScoreHistoryUpdateFinal.find(
        {"UserOid" :ObjectId("55d6e7c0f0639509b4c7a83b")}).count()

I have the same error

styvane
  • 59,869
  • 19
  • 150
  • 156
  • possible duplicate of [search by ObjectId in mongodb with pymongo](http://stackoverflow.com/questions/16073865/search-by-objectid-in-mongodb-with-pymongo) – styvane Aug 25 '15 at 14:37

1 Answers1

0

To query your document you need to import ObjectId

from bson.objectid import ObjectId

Also the best way to do this is:

ursor2 = db.BrandScoreHistoryUpdateFinal.count(
        {"UserOid": ObjectId("55d6e7c0f0639509b4c7a83b")})
styvane
  • 59,869
  • 19
  • 150
  • 156