Duplicating a mongodb document with new objectid uing mongoengine

Viewed 84

I want to Duplicate an existing document and update a field and save it to the same database but how am I supposed to generate a new objectID? or the easier one how to just drop this field so that when saving mongoengine generates a new one? I want to do this because it already gives me the error about same _id.

1 Answers

Best is to unset the _id field and leave mongodb to autogenerate it , the other option is to generate it yourself , example via mongo shell:

> ObjectId.fromDate(ISODate("2018-01-24T06:09:42Z"))
ObjectId("5a6823260000000000000000")
Related