Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mongodb中参数为$size,参数为$in_Mongodb - Fatal编程技术网

mongodb中参数为$size,参数为$in

mongodb中参数为$size,参数为$in,mongodb,Mongodb,我有以下查询,错误是“”\t\“errmsg\”:“$size需要一个数字\”,“,基本上我不能使用$in作为参数,为什么?如果有匹配项,$in不是在输入号码吗?我也很难解决这个问题,如果我使用另一个注释中的$或,我会得到一个警告,我不能连续使用两个$或 db.Movies.find({ "company.country": {$in: ["Brazil", "Mexico","USA"]}, $o

我有以下查询,错误是“
”\t\“errmsg\”:“$size需要一个数字\”,“
,基本上我不能使用
$in
作为参数,为什么?如果有匹配项,
$in
不是在输入号码吗?我也很难解决这个问题,如果我使用另一个注释中的
$或
,我会得到一个警告,我不能连续使用两个
$或

db.Movies.find({
    "company.country": {$in: ["Brazil", "Mexico","USA"]},
     $or: [{"company.start_year": {$gte: 1990, $lte: 1995}}, {"company.start_year": {$gte: 2005, $lte:2010}}],
     actors: {$size: {$in: [2, 4, 6, 8]}},
    //{$or: [{actors: {$size: 2}}, {actors: {$size: 4}}, {actors: {$size: 8}}]},
     ratings: {$gte: 7}
}, {_id: 0, movie_name: 1, })
你必须使用接线员。试试这个:

{ $expr: { $in: [{ $size: "$actors" }, [2, 4, 6, 8]] } }
{
   "company.country": { $in: ["Brazil", "Mexico", "USA"] },
   $and: [
      { $or: [{ "company.start_year": { $gte: 1990, $lte: 1995 } }, { "company.start_year": { $gte: 2005, $lte: 2010 } }] },
      { $or: [{ actors: { $size: 2 } }, { actors: { $size: 4 } }, { actors: { $size: 8 } }] }
   ],
   ratings: { $gte: 7 }
}
如果您更喜欢
$或
,请使用此选项:

{ $expr: { $in: [{ $size: "$actors" }, [2, 4, 6, 8]] } }
{
   "company.country": { $in: ["Brazil", "Mexico", "USA"] },
   $and: [
      { $or: [{ "company.start_year": { $gte: 1990, $lte: 1995 } }, { "company.start_year": { $gte: 2005, $lte: 2010 } }] },
      { $or: [{ actors: { $size: 2 } }, { actors: { $size: 4 } }, { actors: { $size: 8 } }] }
   ],
   ratings: { $gte: 7 }
}
你必须使用接线员。试试这个:

{ $expr: { $in: [{ $size: "$actors" }, [2, 4, 6, 8]] } }
{
   "company.country": { $in: ["Brazil", "Mexico", "USA"] },
   $and: [
      { $or: [{ "company.start_year": { $gte: 1990, $lte: 1995 } }, { "company.start_year": { $gte: 2005, $lte: 2010 } }] },
      { $or: [{ actors: { $size: 2 } }, { actors: { $size: 4 } }, { actors: { $size: 8 } }] }
   ],
   ratings: { $gte: 7 }
}
如果您更喜欢
$或
,请使用此选项:

{ $expr: { $in: [{ $size: "$actors" }, [2, 4, 6, 8]] } }
{
   "company.country": { $in: ["Brazil", "Mexico", "USA"] },
   $and: [
      { $or: [{ "company.start_year": { $gte: 1990, $lte: 1995 } }, { "company.start_year": { $gte: 2005, $lte: 2010 } }] },
      { $or: [{ actors: { $size: 2 } }, { actors: { $size: 4 } }, { actors: { $size: 8 } }] }
   ],
   ratings: { $gte: 7 }
}