mongodb/mongoose 聚合为或 returns null
mongodb/mongoose aggregate with or returns null
为什么这不起作用?
我无法使用 $or 条件。然而,当我简单地将两个正则表达式放在一个联合语句中时,结果 returns。
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
});
为什么这不起作用?
我无法使用 $or 条件。然而,当我简单地将两个正则表达式放在一个联合语句中时,结果 returns。
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
});