I'm trying to write a query to find 2 individual documents dated before and after today, I need the values returned as a cursor as this is a Meteor publication (Perhaps not relevant).
I am currently using this
const today = new Date();
const before = db.lesson.findOne({lsn_id:kjsflf, lsn_dt:{$lte:today}}, {limit:1});
const after = db.lesson.findOne({lsn_id:kjsflf, lsn_dt:{$gte:today}}, {limit:1});
Ideally the result would be something like this:
return db.lesson.find({BEST QUERY EVER});
If you are trying to combine these two queries you can try using MongoDB's $or:
db.lesson.find({
lsn_id: kjsflf,
$or: [
{ lsn_dt: { $lte: today }},
{ lsn_dt: { $gte: today }}
]}, { limit: 2 });
This works well if there only exists one and only one document before "today" and one and only one document after "today". If there are other documents it will retrieve the first two documents it finds.
https://docs.mongodb.com/manual/reference/operator/query/or/