node.js - $lookup 在我的节点 js 中不起作用,因为它在我的指南针测试中起作用
问题描述
所以我在我的 nodejs 应用程序上有一个聚合,它不是在查找引用的文档,但是当我在 compass 上手动测试它时,它会显示结果。所以也许我对猫鼬做错了什么。这是我的应用程序中的代码
const notifications = await Notification.aggregate([
{
$match: {
destinationUserId: userId
}
},
{
$lookup: {
from: "rides",
localField: "ride",
foreignField: "_id",
as: "rideInfo"
}
}
]).skip(offset).limit(limit).sort(`${order}${fieldForOrder}`);
console.log({notifications});
当我这样做时,我会在 console.log 上得到这个结果
{
notifications: [
{
_id: 5e9ca58c486ac8a1e0bc80e5,
authorUserId: 'abfb258d-3ce8-40a4-a214-45afe7c71687',
destinationUserId: '1ef488c7-9078-4378-9ac9-1e9f650048e5',
title: 'Your ride is due',
message: 'You should be on way to your destination. You have 1 passengers. ',
state: 'read',
rideId: 5e9ca4d4486ac8a1e0bc80e4,
__v: 0,
createdAt: 2020-04-19T19:25:00.014Z,
updatedAt: 2020-04-19T21:26:09.079Z,
rideInfo: []
}
]
}
所以我在rideInfo 中得到一个空数组。
解决方案
推荐阅读
- php - 如何将 php 类扩展为覆盖其功能的类
- angular - 更改使用 ngFor 的按钮内的文本
- python - 在 pyiinstaller 中找不到 client_secrets.json
- ruby-on-rails - 如何调试“Articles#show 中的 NoMethodError”?
- python - 使用 python 应用程序进行多处理以缩短当前 36 小时的运行时间
- python - 我可以选择手动更新我的神经网络中的权重以允许基本上无限的批量大小吗?
- javascript - 使用 InjectionToken 进行注入?
- php - 如何在 Wordpress 中显示图像
- ios - IOS app crash with CFNetwork,但找不到问题
- ios - 在 mapbox 地图上用一根手指缩放似乎也改变了中心位置?