我有以下查詢:無法排序沒有索引蒙戈查詢
{ "loc" : { "$near" : [ 32.08 , 34.779] , "$maxDistance" : 0.04499640028797696} , "isCreated" : true , "loc.venueName" : null}
排序方式:
{"lastActiveTime":-1}
限量100個文檔。
祿 - 包含密鑰(緯度,經度,venueName)
isCreated嵌入文檔 - 布爾
lastActiveTime - 最新
我收到例外:
org.springframework.data.mongodb.UncategorizedMongoDbException:sort()沒有索引的數據太多。添加索引或指定較小的限制;
我已經嘗試了所有類型的索引,化合物的變化,而不是化合物,但我仍然得到了上面的異常,試圖...
{'loc':'2d', 'lastActiveTime':-1}
和:
{'lastActiveTime':-1}
哪我需要在文檔中創建索引才能使查詢成功?
MongoDB的版本是2.0.6
這是例如文件(連同有關鍵):
{
"_id" : "5d5085601208aa918bea3c1ede31374d",
"gender" : "female",
"isCreated" : true,
"lastActiveTime" : ISODate("2013-04-08T11:30:56.615Z"),
"loc" : {
"lat" : 32.082230499955806,
"lon" : 34.813542940344945,
"locTime" : NumberLong(0)
}
}
您是否嘗試過,'{LOC: '2D',isCreated:1,loc.venueName:1,lastActiveTime :-1}'? – Sammaye 2013-04-08 10:33:57
你可以向你的問題添加一個示例文檔嗎?只是爲了確保查詢適合於開始。 – 2013-04-08 11:32:41
添加示例文件..in文件loc.venueName爲空/不存在 – 2013-04-08 11:44:53