当我尝试在聚合管道中使用Error: Arguments must be aggregate pipeline operators
时,我收到错误allowDiskUse
。我遵循Mongodb网站的结构但仍然失败,为什么?
coin.aggregate([
{
$match: {
exchange: exchange
}
},
{
$unwind: "$coin_sum"
},
{
// match query with array (here is no longer array)
$match: {
$or: [
{ "coin_sum.granularity": "minute", "coin_sum.timeStamp": { $lt: (expiration.minute) ? parseInt(timeStamp) - expiration.minute : 0 } },
{ "coin_sum.granularity": "hour", "coin_sum.timeStamp": { $lt: (expiration.hour) ? parseInt(timeStamp) - expiration.hour : 0 } },
{ "coin_sum.granularity": "day", "coin_sum.timeStamp": { $lt: (expiration.day) ? parseInt(timeStamp) - expiration.day : 0 } },
{ "coin_sum.granularity": "month", "coin_sum.timeStamp": { $lt: (expiration.month) ? parseInt(timeStamp) - expiration.month : 0 } }
]
}
},
{
$group: {
_id: "$exchange",
remove_coins: {
$addToSet: {
high: "$coin_sum.high",
low: "$coin_sum.low"
}
}
}
}
],
{
allowDiskUse: true,
cursor: {
batchSize: 1000
}
}).then((res) => {
console.log(res);
});
答案 0 :(得分:0)
我想通了
nouveautes.forEach(function(nouveaute) {
console.log(nouveaute.createdAt.toLocaleString());
nouveaute.createdAt = nouveaute.createdAt.toLocaleString();
console.log(nouveaute.createdAt.getMonth());
nouveaute.createdAt = nouveaute.createdAt.getMonth() + " " + nouveaute.createdAt.getYear();
console.log(nouveaute.createdAt);
});
答案 1 :(得分:0)
coin.aggregate(
{ "$facet": {
{
$match: {
exchange: exchange
}
},
{
$unwind: "$coin_sum"
},
{
$match: {
$or: [
{ "coin_sum.granularity": "minute", "coin_sum.timeStamp":
{ $lt: (expiration.minute) ? parseInt(timeStamp) -
expiration.minute : 0 } },
{ "coin_sum.granularity": "hour", "coin_sum.timeStamp": {
$lt: (expiration.hour) ? parseInt(timeStamp) -
expiration.hour : 0 } },
{ "coin_sum.granularity": "day", "coin_sum.timeStamp": {
$lt: (expiration.day) ? parseInt(timeStamp) -
expiration.day : 0 } },
{ "coin_sum.granularity": "month", "coin_sum.timeStamp": {
$lt: (expiration.month) ? parseInt(timeStamp) -
expiration.month : 0 } }
]
}
},
{
$group: {
_id: "$exchange",
remove_timeStamp: {
$addToSet: "$coin_sum.timeStamp"
},
remove_granularity: {
$addToSet: "$coin_sum.granularity"
}
}
}
}
).allowDiskUse(true).cursor({batchSize : 1000})
.then((res) => { //do something });