MongoError: Can't canonicalize query: BadValue bad order array [2]

I have a database with the following document structure:

{
    "_id" : ObjectId("520bea012ab230549e749cff"),
    "Day" : 1,
    "Time" : 54,
    "State" : "Vermont",
    "Airport" : "BTV",
    "Temperature" : 39,
    "Humidity" : 57,
    "Wind Speed" : 6,
    "Wind Direction" : 170,
    "Station Pressure" : 29.6,
    "Sea Level Pressure" : 150
}

I need to find the most high 'Temperature' for each 'State' (ieeg there are 100 document with 'State':'Vermont') and add entry 'month_high':true into this document (that has the most high temperature)

Here is my code: http://pastebin.com/UbACLbSF

But when I run the program in shell I get the following error:

MongoError: Can't canonicalize query: BadValue bad order array [2]


你应该传入一个对象,而不是一个数组

cursor.sort({"State": 1, "Temperature": -1});

You just need the 'State' and 'Temperature', right? So try to project it before sorting. I've tested the following code and it worked:

var query = {};
var projection = { 'State':1, 'Temperature':1 };
var options = { 'sort' : [['State',1], ['Temperature',-1]] };

var cursor = db.collection('data').find(query, projection, options);
链接地址: http://www.djcxy.com/p/28136.html

上一篇: 将依赖关系注入ES2015模块

下一篇: MongoError:无法规范化查询:BadValue坏秩序数组[2]