0
我有一個集合,它具有唯一的_id
字段,但在transactionreceipt
字段中具有重複值。我想通過獨特的transactionreceipt
將其過濾出來,並且我想要該記錄的完整文檔數據。這可能嗎?根據唯一ID選擇完整記錄mongodb
我讀的只有索引可以從使用不同的取得..有什麼我可以得到完整的文件也。
我的數據集:
{"_id": {"$oid": "580af4ce1b407e114sdvsdbf"},
"transactionreceipt":"734416173864583200",
"type":"recharge"
},
{"_id": {"$oid": "580af4ce1b407f495sagfdgaed"},
"transactionreceipt":"734416173864583200",
"type":"recharge"
},
{"_id": {"$oid": "580af4ce1b407safasfe114bf"},
"transactionreceipt":"734585659418738700",
"type":"recharge"
},
{"_id": {"$oid": "580af4ce1b407f4956436sdg"},
"transactionreceipt":"734585659418738702",
"type":"recharge"
},
{"_id": {"$oid": "580af4ce1b407f495safasgvd"},
"transactionreceipt":"734723784694562800",
"type":"recharge"
},
{"_id": {"$oid": "580af4ce1b407f495325ds"},
"transactionreceipt":"734723784694562808",
"type":"recharge"
}
和查詢會是什麼樣
var tx = db.usertransactions.distinct("transactionreceipt",{"type" : "recharge"})
tx.forEach(statistics=>{
printjson(parseFloat(statistics));// i want all details to be displayed here
}
)
我只能得到transactionreceipt
這裏,沒有別的。我哪裏錯了?有沒有可以做到這一點的任何聚合函數?