MongoDB聚合$ lookup以及游标和管道错误

时间:2018-07-22 23:26:35

标签: mongodb mongoose aggregation-framework

我正在尝试运行此聚合以针对MongoDB与Mongoose创建持久连接:

await HourLog.aggregate([
{
  $lookup: {
    from: 'timeentries',
    localField: '_id',
    foreignField: 'hourLog',
    as: 'timeEntries'
  }
},
  { $out: 'hourlogs' }
]);

使用Mongo 3.6.6版和Mongoose 4.8.7版

我收到此错误:

Error: The 'cursor' option is required, except for aggregate with the explain argument

我尝试添加光标选项:

  await HourLog.aggregate([
{
  $lookup: {
    from: 'timeentries',
    localField: '_id',
    foreignField: 'hourLog',
    as: 'timeEntries'
  }
},
  { $out: 'hourlogs' }
], { $cursor: { } });

但是我收到一个新错误:

Error: Arguments must be aggregate pipeline operators

有什么想法吗?

0 个答案:

没有答案