mongos> db.system.views.find({"viewOn" : "ci_basic_custinfo_new_20180110_1"}) { "_id" : "loan_his.ci_basic_custinfo_new", "viewOn" : "ci_basic_custinfo_new_20180110_1", "pipeline" : [ ] } { "_id" : "loan_his.ci_basic_custinfo", "viewOn" : "ci_basic_custinfo_new_20180110_1", "pipeline" : [ ] } mongos> db.ci_basic_custinfo_new.aggregate([{$limit:1}]) { "_id" : ObjectId("5a56dccc7bcaf49a450af5f0"), "objcod" : "14439", "objtype" : "3", "customer_id" : "XXX" } mongos> db.ci_basic_custinfo.aggregate([{$limit:1}]) assert: command failed: { "ok" : 0, "errmsg" : "Namespace loan_his.ci_basic_custinfo is a view, not a collection", "code" : 166, "codeName" : "CommandNotSupportedOnView" } : 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 2018-01-12T00:22:32.897+0800 E QUERY [thread1] Error: command failed: { "ok" : 0, "errmsg" : "Namespace loan_his.ci_basic_custinfo is a view, not a collection", "code" : 166, "codeName" : "CommandNotSupportedOnView" } : 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 mongos> db.ci_basic_custinfo.aggregate([{$limit:1}]) assert: command failed: { "ok" : 0, "errmsg" : "Namespace loan_his.ci_basic_custinfo is a view, not a collection", "code" : 166, "codeName" : "CommandNotSupportedOnView" } : 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 mongos> exit bye ///////// restart the mongos service ///////////////////// [root@mongodb220 json]# service mongos restart Restarting mongos (via systemctl): [ OK ] [root@mongodb220 json]# [root@mongodb220 json]# [root@mongodb220 json]# ml MongoDB shell version v3.4.7 connecting to: mongodb://127.0.0.1:27017/loan_his MongoDB server version: 3.4.7 2018-01-12T00:23:22.176+0800 I CONTROL [main] mongos> db.ci_basic_custinfo.aggregate([{$limit:1}]) { "_id" : ObjectId("5a56dccc7bcaf49a450af5f0"), "objcod" : "14439", "objtype" : "3", "customer_id" : "XXX" } mongos> /////////////////// db.view.count() sometimes works sometimes doesn't ////// mongos> db.system.views.find({viewOn:"bifm02_20180115_1"}) { "_id" : "loan_his.bifm02", "viewOn" : "bifm02_20180115_1", "pipeline" : [ ] } mongos> db.bifm02.count() 3736 mongos> mongos> db.bifm02.count() 2018-01-11T23:01:12.001+0800 E QUERY [thread1] Error: count failed: { "shards" : { }, "cause" : { "ok" : 0, "errmsg" : "Namespace loan_his.bifm02 is a view, not a collection", "code" : 166, "codeName" : "CommandNotSupportedOnView" }, "code" : 166, "ok" : 0, "errmsg" : "failed on : replset_sh220" } : _getErrorWithCode@src/mongo/shell/utils.js:25:13 DBQuery.prototype.count@src/mongo/shell/query.js:383:11 DBCollection.prototype.count@src/mongo/shell/collection.js:1700:12 @(shell):1:1