I am trying to convert an id string to an ObjectId()
I have the following imports:
from pymongo import MongoClient
import pymongo
from bson.objectid import ObjectId
If i print:
print(ObjectId(session['id']))
print(ObjectId())
I get the following:
58a09f4255c205690833f9dd
58f7d1606cb710c54a14ae82
Expected:
ObjectId("58a09f4255c205690833f9dd")
ObjectId("58f7d1606cb710c54a14ae82")
FYI:
pymongo==3.4.0
bson==0.4.7
I have tried (with no luck):
import bson
print(bson.ObjectId(session['id']))
print(bson.ObjectId())
printcallsstron each argument, soprint(ObjectId())outputs the result ofstr(ObjectId()). You'll have to callrepr(explicitly):print(repr(ObjectId()))