1. 查看當前服務器的mongo版本信息
2001 $ dpkg -l|grep mongo
ii? mongodb? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1:2.4.9-1ubuntu2? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? amd64? ? ? ? object/document-oriented database (metapackage)
ii? mongodb-clients? ? ? ? ? ? ? ? ? ? ? ? ? 1:2.4.9-1ubuntu2? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? amd64? ? ? ? object/document-oriented database (client apps)
ii? mongodb-dev? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1:2.4.9-1ubuntu2? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? amd64? ? ? ? object/document-oriented database (development)
ii? mongodb-server? ? ? ? ? ? ? ? ? ? ? ? ? ? 1:2.4.9-1ubuntu2? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? amd64? ? ? ? object/document-oriented database (server package)
2. 本地連接mongo服務器,mongo shell運行聚合語句結果報錯
> db.imp_20170503.aggregate([{$group : {_id : "$idfa", total : {$sum : 1}}}])
2017-07-07T10:47:11.952+0800 E QUERY? ? [thread1] TypeError: cmd.cursor is undefined :
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1322:1
@(shell):1:1
3. 在遠程mongo服務器上,直接mongo shell運行:
> db.imp_20170503.aggregate([{$group : {_id : "$idfa", total : {$sum : 1}}}])
{ "result" : [ { "_id" : "idfa", "total" : 11 } ], "ok" : 1 }
4. 發現被坑爹了! 遠程服務器上可以 : MongoDB shell version: 2.4.9
本地shell不行 :
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 2.4.9
WARNING: shell and server versions do not match
5. 上述顯示的"connecting to: mongodb://127.0.0.1:27017"是因為ssh做的端口轉發到本地了。
6. 上述實踐證明,不是mongo版本低導致的。是server和mongo shell版本不匹配導致聚合執行出錯!
7. 奇葩的是,我在本地連接另一個版本的mongo服務器3.2.14(在yunip上),版本也是不匹配的,但是執行完好:
mongo --port 37017
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:37017/
MongoDB server version: 3.2.14
WARNING: shell and server versions do not match
> db.imp_20170503.aggregate([{$group : {_id : "$idfa", total : {$sum : 1}}}])
{ "_id" : "idfa", "total" : 11 }
-------------------------------------------------------------------------------------
yunip服務器上的信息如下,也將端口轉發到本地37017了。
2001 $ dpkg -l|grep mongo
ii? mongodb-org? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 3.2.14? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? amd64? ? ? ? MongoDB open source document-oriented database system (metapackage)
ii? mongodb-org-mongos? ? ? ? ? ? ? ? ? ? ? ? 3.2.14? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? amd64? ? ? ? MongoDB sharded cluster query router
ii? mongodb-org-server? ? ? ? ? ? ? ? ? ? ? ? 3.2.14? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? amd64? ? ? ? MongoDB database server
ii? mongodb-org-shell? ? ? ? ? ? ? ? ? ? ? ? 3.2.14? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? amd64? ? ? ? MongoDB shell client
ii? mongodb-org-tools? ? ? ? ? ? ? ? ? ? ? ? 3.2.14? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? amd64? ? ? ? MongoDB tools
rc? mongodb-server? ? ? ? ? ? ? ? ? ? ? ? ? ? 1:2.4.9-1ubuntu2? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? amd64? ? ? ? object/document-oriented database (server package)
-------------------------------------------------------------------------------------
8. 真不能簡單說是mongo server和shell版本不匹配導致的,但至少有關系。只是生產中的mongo服務器要測試聚合語句,只能在那臺服務器上測試了!