需要帮助的mongo与双重说明,我复制了这一部分:
db.books.aggregate([
{
$group :
{
_id : "$author",
avgCopies:
{
$accumulator:
{
init: function() { // Set the initial state
return { count: 0, sum: 0 }
},
accumulate: function(state, numCopies) { // Define how to update the state
return {
count: state.count + 1,
sum: state.sum + numCopies
}
},
accumulateArgs: ["$copies"], // Argument required by the accumulate function
merge: function(state1, state2) { // When the operator performs a merge,
return { // add the fields from the two states
count: state1.count + state2.count,
sum: state1.sum + state2.sum
}
},
finalize: function(state) { // After collecting the results from all documents,
return (state.sum / state.count) // calculate the average
},
lang: "js"
}
}
}
}
])但是我得到了一个错误"errmsg“:”未知的组运算符'$accumulator'",https://docs.mongodb.com/manual/reference/operator/aggregation/accumulator/#grp._S_accumulator
发布于 2021-02-17 00:47:44
https://stackoverflow.com/questions/65303643
复制相似问题