pymongo - Error getting MongoDB by _Id in Flask -


i can query mongodb , see "_id" value this:

"_id" : bindata(3,"sfgvqwmkzuiwl5dql62j2g==") 

using flask 0.10.1 , pymongo 3.0.3 attempt "find_one" this:

record = db.collection.find_one({'_id': objectid("sfgvqwmkzuiwl5dql62j2g==")}) 

and error:

bson.errors.invalidid: 'sfgvqwmkzuiwl5dql62j2g==' not valid objectid, must 12-byte input or 24-character hex string 

any appreciated.

you storing _id bindata , trying retrive objectid, instead of objectid.

first need convert base64string binary , try search.

bi = binary.binary("sfgvqwmkzuiwl5dql62j2g=="); record = db.collection.find_one({'_id': bi}); 

this work you. convert id binary compare result.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -