I have the following collection:
article {
title: String,
slug: String,
published_at: Date,
...
}
Run Code Online (Sandbox Code Playgroud)
MongoDB version: 4.4.10
Given an article, I want to fetch the immediate next and previous articles depending on the published_at field of that article.
假设我有一篇带有published_atas的文章100。有很多文章的内容published_at小于100,也有很多文章的内容published_at大于100。我希望管道/查询仅获取具有或或最接近可能published_at值的文章。99101
这是我的聚合管道:
const article = await db.article.findOne({ ... });
const nextAndPrev = db.article.aggregate([
{
$match: {
$or: [
{
published_at: { …Run Code Online (Sandbox Code Playgroud)