我在 mongoDb 4.0 中使用此代码,其工作完美无缺,但我的客户端 MongoDb 是 2.6,因此不支持 $dateToString。在 mongoDb 2.6 中是否有使用 $dateToString 的替代品。使用 MongoDb 4.0:db.getCollection('orgData').aggregate([ {$match:{'orgId' : 5} }, {$unwind :'$events.click'}, {'$project' :{'events.click' : 1}}, {$group :{ '_id' :{'$dateToString' : {format: "%Y-%m-%d",date:'$events.click.mongo_datetime'} } ,'count' : {'$sum' : 1} }} ]);输出 :/* 1 */{ "_id" : "2019-03-01", "count" : 1427.0}/* 2 */{ "_id" : "2019-02-28", "count" : 2244.0}但在 MongoDb 2.6 中,我收到错误:assert: command failed: { "errmsg" : "exception: invalid operator '$dateToString'", "code" : 15999, "ok" : 0} : aggregate failedError: command failed: { "errmsg" : "exception: invalid operator '$dateToString'", "code" : 15999, "ok" : 0} : aggregate failed at Error (<anonymous>) at doassert (src/mongo/shell/assert.js:11:14) at Function.assert.commandWorked (src/mongo/shell/assert.js:244:5) at DBCollection.aggregate (src/mongo/shell/collection.js:1149:12) at (shell):1:292019-09-13T17:28:57.980+1000 Error: command failed: { "errmsg" : "exception: invalid operator '$dateToString'", "code" : 15999, "ok" : 0} : aggregate failed at src/mongo/shell/assert.js:13数据库设计:
添加回答
举报
0/150
提交
取消