我正在Mongodb不同的查詢,我有一個集合重複條目,我按照created_at做。但是我想取得沒有重複的價值。如何使用不同查詢在mongodb中查找重複值?
樣品JSON
{
"posts": [{
"id": "580a2eb915a0161010c2a562",
"name": "\"Ah Me Joy\" Porter",
"created_at": "15-10-2016"
}, {
"id": "580a2eb915a0161010c2a562",
"name": "\"Ah Me Joy\" Porter",
"created_at": "25-10-2016"
}, {
"id": "580a2eb915a0161010c2a562",
"name": "\"Ah Me Joy\" Porter",
"created_at": "01-10-2016"
}, {
"id": "580a2eb915a0161010c2bf572",
"name": "Hello All",
"created_at": "05-10-2016"
}]
}
MongoDB的查詢
db.getCollection('posts').find({"id" : ObjectId("580a2eb915a0161010c2a562")})
所以我想了解的MongoDB不同的查詢,請您通過我的帖子,讓我知道。
你是什麼意思發現不同? – hyades
@hyades所以當我做db.collection.find它不會獲取重複的值,它會忽略重複的值,並只顯示唯一的結果... –
你收集有多個條目'id'。如果你想只有一個,你可以嘗試'findOne',它會選擇任意一個隨機的 – hyades