I have a scenario where i need to create a clone of few products in my mongoDB. I use the following code
for single_product in survey_products:
cloned_product = without_keys(single_product, {'_id'})
cloned_product_doc = Product(**cloned_product)
cloned_product_doc.save()
print(cloned_product_doc.id)
print(cloned_product_doc._id)
This creates the records properly which is alright, but in both the print functions, i get None even though i call cloned_product_doc.save() prior to accessing the IDs
How can i get the ID of the new entries?
EDITED
Here is the model definition
class Product(Document):
# model
_id = ObjectIdField()
photo = StringField()
name = StringField()
price = FloatField()
currency = StringField()
class Meta:
db_table = 'product'