我正在與小時數的索引創建的奇怪行爲作鬥爭。我正在嘗試重新構建我的樣本數據,所以在插入新數據之前刪除我的集合,然後在插入新數據之前,我再次創建索引,如下所示。MongoDb EnsureIndex看起來有一個bug
db.GetCollection("Posts").EnsureIndex("Name","Title","Owner");
之後,我試圖執行排序的查詢,但MongoDB的拋出異常,並說
QueryFailure標誌是太多的數據排序(),沒有指標。添加一個索引或指定一個更小的限制
但是,如果我在執行查詢之前將此行代碼db.GetCollection("Post").EnsureIndex("Name");
,它工作沒有問題。然後我意識到,如果我在重建數據之前使用它,它可以工作。在超載方法中應該有一個錯誤或者我錯過了一些東西。
我使用10gen的.NET驅動程序版本1.2和我檢查execure查詢之前哪些指標存在。這是
db.GetCollection("Posts").EnsureIndex("Name","Title","Owner");
db.GetIndexes();//result
[0]: { "v" : 1, "key" : { "_id" : 1 }, "ns" : "Posts", "name" : "_id_" }
[1]: { "v" : 1, "key" : { "Name" : 1, "Title" : 1, "Owner" : 1 }, "ns" : "Posts", "name" : "Name_1_Title_1_Owner_1_" }
db.GetCollection("Posts").EnsureIndex("Title") // i call this for other indexes too
db.GetIndexes();
[0]: { "v" : 1, "key" : { "_id" : 1 }, "ns" : "Posts", "name" : "_id_" } [1]: { "v" : 1, "key" : { "Name" : 1 }, "ns" : "Posts", "name" : "Name_1" } [2]: { "v" : 1, "key" : { "Title" : 1 }, "ns" : "Posts", "name" : "Title_1" } [4]: { "v" : 1, "key" : { "Owner" : 1 }, "ns" : "Posts", "name" : "Owner_1" }
重現在shell中。如果這樣做或者你做錯了什麼,或者你使用的驅動程序有問題。 –