mongodb / mongoose聚合或返回null

为什么这不起作用?

我无法使用$或条件工作。 但是,当我简单地把两个正则expression式Expessions放在一个联合声明中时,它会返回结果。

Zip.aggregate( { $or: [ {$match: {'ort': regExp}}, {$match: {'ortsteile.ortsteil': regExp}} ] }, function(err, results) { //returns null }); // while this returns results: Zip.aggregate( {$match: {'ort': regExp, 'ortsteile.ortsteil': regExp}}, function(err, results) { //returns a list of results }); 

 Zip.aggregate( { $match: { $or : [ { "ort":regExp }, { "ortsteile.ortsteil": regExp } ] } }, function(err, results) { //returns result }); 

你的查询是错误的。

 Zip.aggregate({ $match: { $or : [ { 'ort':regExp }, { 'ortsteile.ortsteil': regExp } ] }}, function(err, results) { //your code to handle results });