I have an object that has a parent class that may or may not set a _id field.
In this case, the _id field is not set and I pass an object through to
collection.insertOne(object)
Normally mongo generates a ObjectId() for a _id that isn't specified, but for some reason whenever _id is specified by a parent class and is not set, it is generating an id, bug is saving the id as a string in the database rather than an ObjectId.
What I'm passing through
{ "name" : "name" }
Expected:
{ "_id" : ObjectId("5cb89a7cf5e722a3d493ce8b"), "name" : "name" }
Actual:
{ "_id" : "5cb89a7cf5e722a3d493ce8b", "name" : "name" }
What I think is happening is that it sees that the parent class has a _id field, but can't find it, causing somthing like this to be passed through.
{ "_id" : null, "name" : "name" }
and as a result mongo doesn't generate an ObjectId but a string.
Is this a bug?
Thanks in advance!