此对象已经是运算符表达式,不能用作文档表达式

时间:2017-10-24 10:20:30

标签: mongodb

我在执行mongodb中的以下命令时遇到错误:

db.trans.aggregate(
   [
  { $match: {"cno":89}},
  { $group: { _id: [ $dateToString: { format: "%Y-%m-%d", date: "$transactiondate" },types:"$type"], count: { $sum: 1 } } }])

我想按交易日期和类型进行分组。

错误是:

assert: command failed: {
    "ok" : 0,
    "errmsg" : "this object is already an operator expression, and can't be used as a document expression (at 'types')",
    "code" : 15990
} : aggregate failed_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:16:14
assert.commandWorked@src/mongo/shell/assert.js:370:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1319:5
@(shell):1:1

2017-10-24T15:38:35.498+0530 E QUERY    [thread1] Error: command failed: {
    "ok" : 0,
    "errmsg" : "this object is already an operator expression, and can't be used as a document expression (at 'types')",
    "code" : 15990
} : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:16:14
assert.commandWorked@src/mongo/shell/assert.js:370:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1319:5
@(shell):1:1

0 个答案:

没有答案