Yes it is perfectly fine to use a random value for an object id, if some value is present in _id
field of a document being stored, it is treated as objectId.
Since _id
field is always indexed, and primary key, you need to make sure that different objectid is generated for each object.
There are some guidelines to optimize user defined object ids :
https://docs.mongodb.com/manual/core/document/#the-id-field.