我討厭這種問題,但也許你可以指出我明顯。我正在使用Mongo 2.2.2。集合框架中停止正常工作
我有一個集合(在副本集)與6M文件有字符串字段名爲用戶名我有索引。該指數並不是唯一的,但最近我做出了獨特的評價。突然之後,查詢給了我重複的虛假警報。
db.users.aggregate(
{ $group : {_id : "$username", total : { $sum : 1 } } },
{ $match : { total : { $gte : 2 } } },
{ $sort : {total : -1} });
返回
{
"result" : [
{
"_id" : "davidbeges",
"total" : 2
},
{
"_id" : "jesusantonio",
"total" : 2
},
{
"_id" : "elesitasweet",
"total" : 2
},
{
"_id" : "theschoolofbmx",
"total" : 2
},
{
"_id" : "longflight",
"total" : 2
},
{
"_id" : "thenotoriouscma",
"total" : 2
}
],
"ok" : 1
}
我測試了樣品採集與幾個文件此查詢,它按預期工作。
您確定唯一索引已成功創建嗎?如果有現有的dups,除非設置了'dropDups:true'選項,否則它將無法創建。參見[docs](http://docs.mongodb.org/manual/core/indexes/#drop-duplicates)。 – JohnnyHK
是的。當我查詢'db.users.find({username:「thenotoriouscma」})'時,我可以看到只有一個文檔。 – expert