聚合管道後,我得到一個對象列表,但沒有辦法檢索第N個對象。如何在mongodb中進行聚合後訪問特定元素?
參見:
http://docs.mongodb.org/manual/reference/operator/aggregation/group/#retrieve-distinct-values
的文檔具有輸出像這樣:
{ "_id" : 1, "item" : "abc", "price" : 10, "quantity" : 2, "date" : ISODate("2014-03-01T08:00:00Z") }
{ "_id" : 2, "item" : "jkl", "price" : 20, "quantity" : 1, "date" : ISODate("2014-03-01T09:00:00Z") }
{ "_id" : 3, "item" : "xyz", "price" : 5, "quantity" : 10, "date" : ISODate("2014-03-15T09:00:00Z") }
{ "_id" : 4, "item" : "xyz", "price" : 5, "quantity" : 20, "date" : ISODate("2014-04-04T11:21:39.736Z") }
{ "_id" : 5, "item" : "abc", "price" : 10, "quantity" : 10, "date" : ISODate("2014-04-04T21:23:13.331Z") }
這是一組對象,但它不是在一個列表,所以你不能做的東西一樣:
results [1]獲取第二個對象。你應該如何與這個團隊互動?