MongoDB return True if document exists

后端 未结 6 1070
星月不相逢
星月不相逢 2020-12-14 01:39

I want to return true if a userID already exists and false otherwise from my collection.I have this function but it always returns True.

def alr         


        
6条回答
  •  感动是毒
    2020-12-14 02:21

    I guess am very late to post the solution. Anyways i have encountered same problem today and following worked for me. Hope this help to others.

    return db.mycollection.find({'UserIDS': newID}).count > 0
    

提交回复
热议问题