I am fairly new to working with MongoDB.
I need to retrieve the previous record of a given record in a MongoDB collection.
- Is it possible to do this with "_id = ObjectId(...)" field?
- If not, will we have to explicitly insert a key with a sequential value to identify the previous record to the given one? (Assume that there's no sequential key/value pair in the current collection)
Would greatly appreciate any help. Thank you.
May i suggest use indexes for best performance.
As an example: Create Indexes:
Next query looks like:
Previous query looks like: