MongoDB的。按$ MAX和$ EQ条件

时间:2016-01-12 09:39:53

标签: mongodb mongodb-query

{
   "_id": 1,
   "values":[
      {
         "value1":10,
         "value2":12,
         "value3":30
      },
      {
         "value1":20,
         "value2":12,
         "value3":100
      },
      {
         "value1":30,
         "value2":14,
         "value3":50
      }
   ]
}
{
   "_id": 2,
   "values":[
      {
         "value1":10,
         "value2":12,
         "value3":60
      },
      {
         "value1":20,
         "value2":12,
         "value3":80
      },
      {
         "value1":30,
         "value2":14,
         "value3":70
      }
   ]
}

我想找到哪个文档(例如):

values.value1 = 20
values.value2 = 12
values.value3 is max of all values.value3

我想获得一个包含数组元素的文档。例如:

{
   "_id": 1,
   "values":[
      {
         "value1":20,
         "value2":12,
         "value3":100
      }
   ]
}

或以分类的形式。具有最大value.value3元素的文档必须是具有最大值的数组的第一个元素.value3必须是第一个。例如:

{
   "_id": 1,
   "values":[
     {
         "value1":20,
         "value2":12,
         "value3":100
      },
      {
         elements...
      }
   ]
}
{
   "_id": 2,
   "values":[
      {
         elements...
      }
   ]
}

0 个答案:

没有答案