How do mongodb query statements merge query results?

  mongodb, question

How do you want to query three records in one sentence, including the current record, the previous record and the next record?
Only the _id of the current record is known, and the adjacent records need to be sorted by another time field.

It’s hard to use simple sentences, at least my range feels unrealistic.
I can offer some ideas:

  1. Use db.coll.find({},{ “to display only one column of data, or a few columns, the less the better, the greater the amount of data, because the following sorting operation” })$natual:1 after sorting, assign the value to cursor, and then use two variables in forEach () to save the current data and the previous data until the matching condition is successful, and then you can return the previous and the current three data.
    There may be other better internal methods, welcome plank brick

  2. Another method is to add a column of ordered numbers or characters based on the above regular data of $ natural: 1, then save it to another new table, then query the matching data of the new table according to the ID of the new table, and finally query the data before and after again through the found orderly added column of KEY:value.