我正在尝试在Meteor应用程序中使用MongoDB聚合。我正在使用流星1.11,后者使用MongoDB 4.2.8。我使用Robo 3T构建并测试了聚合管道,还使用Mongo Shell对其进行了测试。在这些情况下,它可以正常工作,但我无法在Meteor方法中使用它。
我将问题缩小到比赛阶段,这是第一阶段。当以Meteor方法运行时,此阶段似乎与集合中的所有文档匹配。在Robo 3T中运行时,它将返回4个文档。这是我在Meteor方法中运行它的方式:
MyCollection
.rawCollection()
.aggregate([{$match: {vocabularyName: "IPF", type: "T"}}])
.toArray()
.then(docs => {
console.log(`got ${docs.length} docs`);
console.log(docs[0]);
console.log(docs[1]);
})
.catch(error => console.log(`error ${error} in db_methods`));
MyCollection中的每个文档都包含一个具有不同值的“类型”字段;大多数(但不是全部)包含“ vocabularyName”字段。当我在Meteor方法中运行此命令时,返回的数组大小与总文档数匹配,并且前两个结果文档完全不包含vocabularyName字段,并且不包含“ type:'S'”。这没有任何意义。
我猜想我也尝试过这个管道,但是没什么区别:
[ {"$match": {"$and": [{ "vocabularyName": "IPF"}, {"type": "T"}]}} ]