This is the first time I am trying to connect to this mongo instance, which is setup by my ex-colleague. when I run "show dbs", I have seen such message:
rs0:SECONDARY> show dbs
2022-01-05T18:33:11.282+0000 E QUERY [js] uncaught exception: Error: listDatabases failed:{
"operationTime" : Timestamp(1641407590, 1),
"ok" : 0,
"errmsg" : "not master and slaveOk=false",
"code" : 13435,
"codeName" : "NotMasterNoSlaveOk",
"$clusterTime" : {
"clusterTime" : Timestamp(1641407590, 1),
"signature" : {
"hash" : BinData(0,"...="),
"keyId" : NumberLong("...")
}
}
} :
_getErrorWithCode#src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs/<#src/mongo/shell/mongo.js:135:19
Mongo.prototype.getDBs#src/mongo/shell/mongo.js:87:12
shellHelper.show#src/mongo/shell/utils.js:906:13
shellHelper#src/mongo/shell/utils.js:790:15
#(shellhelp2):1:1
rs0:SECONDARY>
Any ideas what could be wrong ?
Thanks,
Jack
Following is the screenshot How I got that failure.
You need to execute:
rs.slaveOk()
From the SECONDARY to allow show dbs after ...
Related
I am unable to authenticate using IAM roles which are added to the cluster.
Currently, There is a Role created and attached with the Ec2 instance. Using the same role while connecting to the DB and running any command. I am getting the following error.
error: {
"operationTime" : Timestamp(1635767862, 1),
"ok" : 0,
"errmsg" : "command find requires authentication",
"code" : 13,
"codeName" : "Unauthorized",
"$clusterTime" : {
"clusterTime" : Timestamp(1635767862, 1),
"signature" : {
"hash" : BinData(0,"WibtM8VK2aorci9mA6QNyP/ummU="),
"keyId" : NumberLong("7023742477949468676")
}
}
}
Has anyone ever faced any issue like this with IAM roles and MongoDB Atlas mongo?
Installed a fresh instance of mongodb 3.6 on Ubuntu 16.x
While creating user mongo is giving error as Error: couldn't add user: not master
also same error with show dbs
{
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { listDatabases: 1.0, lsid: { id: UUID(\"f9e0590a4-b20a-b21b9eecf627\") }, $db: \"admin\" }",
"code" : 13,
"codeName" : "Unauthorized"
}
Replication is not enabled
{
"info" : "run rs.initiate(...) if not yet done for the set",
"ok" : 0,
"errmsg" : "no replset config has been received",
"code" : 94,
"codeName" : "NotYetInitialized"
}
Why this mongo instance is behaving like slave when its not configured to do so.
I have added hosts entries for other slave instances but not initialised them yet.
I'm currently trying the aggregations with MongoDB using the json found here : http://media.mongodb.org/zips.json
So, I imported it thousands of time and then I tried this command :
db.CO_villes.aggregate({$group:{_id:"$state",population:{$sum:"$pop"}}})
And I got this error :
2019-04-24T13:49:19.579+0000 E QUERY [js] Error: command failed: {
"ok" : 0,
"errmsg" : "unrecognized field 'mergeByPBRT'",
"code" : 9,
"codeName" : "FailedToParse",
"operationTime" : Timestamp(1556113758, 2),
"$clusterTime" : {
"clusterTime" : Timestamp(1556113758, 2),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
} : aggregate failed :
I have a sharded cluster with 3 MongoDB instances.
I can face this issue too when I try to get the indexes with "Compass".
I tried to export the data and to remove the id field using the "sed" command (because my Ids were not all with "ObjectID")and to import it but I still face this issue.
I solved my issue by creating a 3.6 cluster instead of a 4.0.6. So I think this is a bug related to the new versions of MongoDB.
I am trying to create a replica in mongodb. I have used the following commands to make a replica. I got the following outputs.
cfg = { _id : "mySet", members : [ { _id : 0, host : "localhost:27017"
} ] }
rs.initiate(cfg)
Output:
{
"ok" : 0,
"errmsg" : "Attempting to initiate a replica set with name mySet, but command line reports 0; rejecting",
"code" : 93,
"codeName" : "InvalidReplicaSetConfig"
}
i get the following output:
017-09-22T14:22:22.093+0530 E QUERY [thread1] ReferenceError: conf is not defined :
#(shell):1:1
When i ran show dbs and rs.config(), i get the following errors:
show dbs
2017-09-22T14:23:56.234+0530 E QUERY [thread1] Error: listDatabases
failed:{
"ok" : 0,
"errmsg" : "not master and slaveOk=false",
"code" : 13435,
"codeName" : "NotMasterNoSlaveOk"
} :
_getErrorWithCode#src/mongo/shell/utils.js:25:13 .
Mongo.prototype.getDBs#src/mongo/shell/mongo.js:62:1
shellHelper.show#src/mongo/shell/utils.js:769:19
shellHelper#src/mongo/shell/utils.js:659:15 .
#(shellhelp2):1:1
> rs.config()
2017-09-22T14:24:23.718+0530 E QUERY [thread1] Error: Could not
retrieve replica set config: {
"info" : "run rs.initiate(...) if not yet done for the set",
"ok" : 0,
"errmsg" : "no replset config has been received",
"code" : 94,
"codeName" : "NotYetInitialized"
} :
rs.conf#src/mongo/shell/utils.js:1276:11
#(shell):1:1
delete all replication and oplog.
use local
db.dropDatabase()
restart the mongo
config = {_id: "repl1", members:[
{_id: 0, host: 'localhost:15000'},
{_id: 1, host: '192.168.2.100:15000'}]
}
rs.initiate(config);
I have a mongodb cluster containing two shards, each a replication set of 3 nodes, and a config server cluster again with three nodes.
All seems to be in order apart from when I attempt to write a collection at the end of an aggregation pipeline using the $out operator:
db.getCollection('restaurants').aggregate([
{$match : {$text : {$search : "steak"}}},
{$out : "steak_restaurants"}
])
This is return the following error:
ailed to execute script.
Error: Assert: command failed: { "ok" : 0, "errmsg" : "listIndexes
failed: { ok: 0.0, errmsg: \"not master and slaveOk=false\", code:
13435, codeName: \"NotMasterNoSlaveOk\" }", "code" : 18631,
"codeName" : "Location18631" } : 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
Error: command failed: { "ok" : 0, "errmsg" : "listIndexes failed: {
ok: 0.0, errmsg: \"not master and slaveOk=false\", code: 13435,
codeName: \"NotMasterNoSlaveOk\" }", "code" : 18631, "codeName" :
"Location18631" } : 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
The mongo shell is connected to a mongos router. If I execute the same against mongod, this works fine.
The error suggests that somehow reading is taking place from a secondary, however, I have not set any read preference and I would have thought that mongos would resolve the primary correctly by itself. Any ideas or insight please?
Appears to only be occurring when executed through Robo 3T. Executing through a raw shell works fine.
I had the same problem today and solved it by removing the "getCollection".
Can you try running:
db.restaurants.aggregate([
{$match : {$text : {$search : "steak"}}},
{$out : "steak_restaurants"}
])