Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/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
Javascript 是否仅显示嵌套数组中满足mongodb条件的元素?_Javascript_Arrays_Node.js_Mongodb - Fatal编程技术网

Javascript 是否仅显示嵌套数组中满足mongodb条件的元素?

Javascript 是否仅显示嵌套数组中满足mongodb条件的元素?,javascript,arrays,node.js,mongodb,Javascript,Arrays,Node.js,Mongodb,以下是我的moviedb收藏: "_id" : ObjectId("59b9501600fcb397d6acd5bb"), "theatreid" : 2, "name" : "carnival cinemas", "location" : "kanjulmarg", "address" : "sec 2,kanjul, Mumbai, Maharashtra 400703", "shows" : [ { "mname" : "bareily

以下是我的moviedb收藏:

 "_id" : ObjectId("59b9501600fcb397d6acd5bb"),
  "theatreid" : 2,
 "name" : "carnival cinemas",
 "location" : "kanjulmarg",
 "address" : "sec 2,kanjul, Mumbai, Maharashtra 400703",
 "shows" : [
      {
              "mname" : "bareily ki barfi",
              "timings" : [
                      10,
                      13,
                      14,
                      16,
                      22
              ]
      },

      {
              "mname" : "Toilet:ek prem katha",
              "timings" : [
                      8,
                      9,
                      14,
                      16,
                      20,
                      23
              ]
      }
  ]


  "_id" : ObjectId("59b9506500fcb397d6acd5bc"),
   "theatreid" : 3,
  "name" : "pheonix pvr",
 "location" : "kurla",
 "address" : "sec 26,kurla, Mumbai, Maharashtra 400701",
 "shows" : [
      {
              "mname" : "shubh mangal savdhan",
              "timings" : [
                      9,
                      11,
                      15,
                      18,
                      20
              ]
      },
      {
              "mname" : "Toilet:ek prem katha",
              "timings" : [
                      8,
                      9,
                      14,
                      16,
                      20,
                      23
              ]
      }
 ]
我想显示电影时间(假设为24小时格式)大于14(下午2点)的节目。 我使用了以下查询:

db.moviedb.find( {"shows.timings": {$gt:14}},  {shows: {$elemMatch: {timings:{$gt: 14}}}}).pretty()
它给出以下输出:

实际值

   "_id" : ObjectId("59b94fc900fcb397d6acd5ba"),
   "shows" : [
           {
                   "mname" : "bareily ki barfi",
                   "timings" : [
                           10,
                           13,
                           15,
                           17,
                           21
                   ]
           }
   ]


   "_id" : ObjectId("59b9501600fcb397d6acd5bb"),
   "shows" : [
           {
                   "mname" : "bareily ki barfi",
                   "timings" : [
                           10,
                           13,
                           14,
                           16,
                           22
                   ]
           }
   ]
但正如所观察到的,它也显示了那些不满足条件的元素(如10,13)。我只是希望只显示那些满足结果的元素。 我希望以以下方式输出

预期的

   "_id" : ObjectId("59b94fc900fcb397d6acd5ba"),
   "shows" : [
           {
                   "mname" : "bareily ki barfi",
                   "timings" : [

                           15,
                           17,
                           21
                   ]
           }
   ]


   "_id" : ObjectId("59b9501600fcb397d6acd5bb"),
   "shows" : [
           {
                   "mname" : "bareily ki barfi",
                   "timings" : [

                           16,
                           22
                   ]
           }
   ]
这是我在使用$filter之后得到的输出,但是如果我手动提供输入数组,它工作得很好

    db.moviedb.aggregate([    {       $project: {         " shows.timings": 
{             $filter: {                input: "$shows.timings",                
as: "item",
 cond: { $gte: [ "$$item", 22 ] }             }          }       }    } ])
"_id" : ObjectId("59b94fc900fcb397d6acd5ba"), " shows" : { "timings" : [ [ 
10, 13, 15, 17, 21 ], [ 8, 11, 14, 17, 20, 22 ] ] } }
"_id" : ObjectId("59b9501600fcb397d6acd5bb"), " shows" : { "timings" : [ [ 
10, 13, 14, 16, 22 ], [ 8, 9, 14, 16, 20, 23 ] ] } }
"_id" : ObjectId("59b9506500fcb397d6acd5bc"), " shows" : { "timings" : [ [ 
9, 11, 15, 18, 20 ], [ 8, 9, 14, 16, 20, 23 ] ] } }
需要做什么?
请帮助。谢谢:)

看起来你可以使用
$filter
来做你想做的事情-可能是@realseanp的重复,我使用了$filter,它仍然显示不满足条件的值。我只想在shows.timings中显示满足条件的元素array@realseanp请检查上面的帖子,我已经添加了$filter的输出。你试过链接帖子的答案了吗?