在Mysql中,我可以從另一個Select中進行選擇。 所以我會問,如果我能在Mongodb做同樣的事情。在mongodb中查找另一個發現
詳細的解釋,我需要在這個collection.So的history
對象與剛剛過去的dateTransaction
中檢索的特定userOwner
的交易,如果這userOwner是不是在過去歷史中,我們shoudn't檢索到此交易。
我起初這個查詢使用:
@Query(value = "{'history':{'$elemMatch':{'userOwner': ?0}}}")
但它返回甚至所有元素那些本userOwner是不是最後一個「dateTransaction」。
所以我的目標是去它返回每次交易剛剛過去dateTransaction與「歷史」陣列的userOwner查詢:
.find({},{dateTransaction: {$slice: 1} }).limit(1)
,做從這個彼此詢問之後。
任何人都有一個想法或例子。
TNX
這是我收集所謂的 「作品」:
{
"_id" : ObjectId("1"),
"history" : [{
"userOwner" : "3",
"dateTransaction" : ISODate("2016-05-30T00:00:00.000+0000"),
}, {
"userOwner" : "1",
"dateTransaction" : ISODate("2016-05-26T00:00:00.000+0000"),
}, {
"userOwner" : "2",
"dateTransaction" : ISODate("2016-05-23T00:00:00.000+0000"),
}
]
}{
"_id" : ObjectId("2"),
"transactions" : [{
"userOwner" : "2",
"dateTransaction" : ISODate("2016-05-26T00:00:00.000+0000"),
}, {
"userOwner" : "3",
"dateTransaction" : ISODate("2016-05-15T00:00:00.000+0000"),
}
]
}{
"_id" : ObjectId("3"),
"transactions" : [{
"userOwner" : "2",
"dateTransaction" : ISODate("2016-05-26T00:00:00.000+0000"),
}, {
"userOwner" : "1",
"dateTransaction" : ISODate("2016-05-15T00:00:00.000+0000"),
}
]
}
作爲例子爲userOwner 2的結果應該是:
{
"_id" : ObjectId("2"),
"transactions" : [{
"userOwner" : "2",
"dateTransaction" : ISODate("2016-05-26T00:00:00.000+0000"),
}, {
"userOwner" : "3",
"dateTransaction" : ISODate("2016-05-15T00:00:00.000+0000"),
}
]
}{
"_id" : ObjectId("3"),
"transactions" : [{
"userOwner" : "2",
"dateTransaction" : ISODate("2016-05-26T00:00:00.000+0000"),
}, {
"userOwner" : "1",
"dateTransaction" : ISODate("2016-05-15T00:00:00.000+0000"),
}
]
}
你能否添加一些冗長?你知道你的頭是什麼,不,我們不:-) – profesor79
我的問題是可以理解的嗎?我需要幫助。 – ShMswi
是否只有一個集合或更多?從select中選擇可以有很多含義? – profesor79