MongoDB return True if document exists
Note: This answer is outdated. More recent versions of MongoDB can use the far more efficient method db.collection.countDocuments. See the answer by Xavier Guihot for a better solution. find doesn’t return a boolean value, it returns a cursor. To check if that cursor contains any documents, use the cursor’s count method: if db.mycollection.find({‘UserIDS’: { “$in”: … Read more