0
votes

I have a high-concurrency and parallelism situation and would like _id fields to be created by MongoDB and not by mongoose, so that I can use the ObjectId timestamps in the _id field to reliably query documents in the order they were inserted.

Is this possible? Right now I don't see how to do this with mongoose, as marking a schema with {_id: false} and trying to save it returns an error document must have an _id before saving.

1

1 Answers

1
votes

Mongoose docs say the _id option only works on subdocuments, hence the error you get (http://mongoosejs.com/docs/guide.html#_id).

It might fit your situation to add a document without mongoose and in a subsequent operation update it through using mongoose (thereby keeping mongoose's Schema functionality etc).