繁体   English   中英

使用mongdb驱动程序2.2.16的Mongodb聚合框架在结果集中给出“未定义”

[英]Mongodb Aggregation framework using mongdb driver 2.2.16 giving “undefined” in resultset

在收到“已贬值”警告后,我刚刚将mongodb驱动程序从1.4升级到了2.2.16。

问题似乎在于如何聚合。 如果删除$ match,它会起作用。 $ match的结果在结果集中给了我“未定义”。

这是我的汇总功能。

 Doc.aggregate( {$match: searchCriteria}, //Removing this gives result {$project: { title: 1, description:1, createdOn:1, extension:1, workflows: 1, enableWorkflow: 1, numPages:1, userid:1, metadata:1, docGalleryId:1, tags:1, status:1, galleryThumbUrl : { $slice: ["$pages.galleryThumbUrl", 1 ] } } }, {$unwind: '$galleryThumbUrl'}, {$sort: {createdOn: -1}}, {$skip: skip}, {$limit: items}, function (err, result) { console.log(result); //This gives Undefined Doc.populate(result, {path: 'userid', select: 'firstName, lastName, userEmail'}, function (err, docCol) { console.log(err, docCol); console.log('items', items); callback({ docs: docCol, showNext: showNext, page: page, items: items }); }); } ); 

searchCriteria是一个对象(不是字符串)。 这是它的样子

{"$and":[{"status":{"$ne":"deleted"}},{"$or":[{"userid":{"$in":["56bf7f25f59d1ff711000005"]}},{"collaboration":{"$elemMatch":{"userid":"56bf7f25f59d1ff711000005"}}}]}]}

就像我之前说的那样,这曾经可以正常工作,但是在更新到2.2.16时不再有效。 多谢您的协助。

如所怀疑的,我必须在我的“ searchCriteria”结构中基本消除双引号。 所以我做了,

searchCriteria = JSON.parse(JSON.stringify(searchCriteria));

它成功了。 这是多余的,可能是一个更好的解决方案,但是目前,这已为我解决了问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM