我有两个收集coin1& coin2,我试图在DESC的日期字段顺序的基础上从两个集合中获取记录。其中coin_id是1
coin1 collection
[{ "_id" : 1, "coin_id" : "1", date: "1516259613150"},
{ "_id" : 2, "coin_id" : "1", date: "1514113680"}]
coin2 collection
[{ "_id" : 1, "coin_id" : "1", date: "1496836604"},
{ "_id" : 2, "coin_id" : "1", date: "1514113680"},
]]
我看起来像这样的结果 - :
[{ "_id" :1, "coin_id" : "1", date: "1516259613150"},
{ "_id" : 2, "coin_id" : "1", date: "1514113680"}.
{ "_id" : 1, "coin_id" : "1", date: "1514113680"},
{ "_id" : 2, "coin_id" : "1", date: "1496836604"}]
我如何获得此记录。
此处的日期为unix日期格式。
答案 0 :(得分:2)
如果您使用mongoose,我认为您可以尝试使用此代码!
Collection.find().sort({'data':'( - or + )1'}).find(function (err, collection){
console.log(collection);
});