我正在尝试通过匹配书集中的书ID字段来从评论集中获取评论。这是我的汇总查询,
static async getBookByID(id) {
return await books.aggregate([
{
$lookup:
{
from: "Comments",
let: { 'book_id': id },
pipeline: [
{
$match:
{ $expr: { $eq: ['$book_id', '$$book_id'] } }
},
{ $project: { 'title': 1, 'comments': 1 } },
{
$sort: {
'date': -1
}
}
],
as: 'comments'
}
}
]);
}
我的测试失败
Comparing two different types of values. Expected string but received undefined.
编辑
评论集合
{"_id":"5a9427658b0beebeb696b14d",
"name":"John Bishop",
"email":"john@fakegmail.com",
"book_id":"573a13a6f29313caabd17bd5",
"text":"Sed odit incidunt totam dolorem nam doloribus. Dignissimos dolore accusamus vel. Cupiditate deserunt esse quisquam quisquam cum.",
"date":"1976-03-16T19:54:28.000Z"}
图书收藏
{"_id":"573a13a6f29313caabd17bd5","title":"Once Upon a Time in Mexico"}