I'm using Swagger+pymongo and I wanted something really simple to convert a string into an ObjectId. How can I do this very easily without touching other db schemas.(Minimal effort)?
Code:
jsonResponse = request.json['business']
# convert business_id Datatype to ObjectId
business_id=ObjectId(jsonResponse['business_id'])
#add business_id (ObjectId)to mongodb
data = collection.insert_one(jsonResponse).inserted_id
return data