Mongo.getDatabaseNames() occasionally throws CommandFailureException - mongodb

We have been having some problems where our mongo connection fails to allow us to get the database names from the DB.
We call the method:
com.mongodb.Mongo.getDatabaseNames()
And 1 out of 100 times, it throws the following exception:
Caused by: com.mongodb.CommandFailureException: { "serverUsed" : "localhost:27017" ,
"errmsg" : "exception: can't open database in a read lock. if db was just closed, consider retrying the query. might otherwise indicate an internal error" , "code" : 15927 , "ok" : 0.0}
at com.mongodb.CommandResult.getException(CommandResult.java:76)
at com.mongodb.CommandResult.throwOnError(CommandResult.java:131)
at com.mongodb.Mongo.getDatabaseNames(Mongo.java:397)
Looking at the mongo code, the database is the internal admin database
public List<String> getDatabaseNames(){
BasicDBObject cmd = new BasicDBObject();
cmd.put("listDatabases", 1);
>>CommandResult res = getDB(ADMIN_DATABASE_NAME).command(cmd, getOptions());
res.throwOnError();
This database is not being deleted, but there are several other databases that could be deleted around this time.
Has anyone else had this problem?

Related

How to insert record to mongoDB6 collection using PutMongo processor in Apache Nifi?

When I am trying to insert the record(json) to mongodb collection. I am getting exception
{ "ok" : 0.0, "errmsg" : "Unsupported OP_QUERY command: insert. The client driver may require an upgrade. For more details see https://dochub.mongodb.org/core/legacy-opcode-removal", "code" : 352, "codeName" : "UnsupportedOpQueryCommand" }
I have MongoDb 6.0 version configured
MongoDb removes Opal_insert operation in new version.How to resolve it ?

MongoDb - command drop requires authentication

I have the following command
mongo clean_collection.js --host localhost --username root --password example
Clean_collection.js file contains:
conn = new Mongo();
db = conn.getDB("MyDb");
var myColl = db.getCollection('MyCollection');
myColl.drop();
But MongoDb returns:
MongoDB shell version v4.2.8
connecting to: mongodb://localhost:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("22d094e1-fb65-46c8-a9e6-386c1678c680") }
MongoDB server version: 4.2.8
2020-07-15T10:33:00.787-0400 E QUERY [js] uncaught exception: Error: drop failed: {
"ok" : 0,
"errmsg" : "command drop requires authentication",
"code" : 13,
"codeName" : "Unauthorized"
} :
_getErrorWithCode#src/mongo/shell/utils.js:25:13
DBCollection.prototype.drop#src/mongo/shell/collection.js:696:15
I'm also using MongoDb .NET Driver and I can drop the collection withou any problems with using .NET driver.

MongoDB Performance Testing Using Jmeter (Connection Issue)

We are trying do performance testing using Jmeter. Database is MongoDB.
Using JSR223 Sampler with Groovy 2.4.10.
import com.mongodb.DB;
import org.apache.jmeter.protocol.mongodb.config.MongoDBHolder;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.DBCollection;
import com.mongodb.WriteConcern;
import com.mongodb.WriteResult;
DB db = MongoDBHolder.getDBFromSource("admin", "databasename", "username", "password");
DBCollection collection = db.getCollection("test");
long count = collection.getCount();
String result = String.valueOf(count);
SampleResult.setResponseData(result.getBytes())
Getting below error.
Response code: 500
Response message: javax.script.ScriptException: com.mongodb.CommandFailureException: { "serverUsed" : "l4abcddb1232/11.20.132.301:27017" , "ok" : 0.0 , "errmsg" : "not authorized on databasename to execute command { count: \"test\", query: {} }" , "code" : 13 , "codeName" : "Unauthorized"}
Above issue in Dev database.
Also, how to connect SSL to connect mongodb database (QC)?
Thank you in advance!
Bharathi
This is more mongodb questions, but see authentication and connection to start working with authorized user and SSL connection.

Issue with mongodb document limit

I am using mongodb 3.0.2 and when I run "top" command :
> db.runCommand( { top: 1 } )
I got the following error message:
2015-06-01T16:36:52.886+0900 E QUERY Error: error: {
"$err" : "BSONObj size: 46060490 (0x2BED3CA) is invalid. Size must be between 0 and 16793600(16MB)",
"code" : 10334
}
at Error ()
at DBQuery.next (src/mongo/shell/query.js:259:15)
at DBCollection.findOne (src/mongo/shell/collection.js:189:22)
at DB.runCommand (src/mongo/shell/db.js:58:41)
at (shell):1:4 at src/mongo/shell/query.js:259
It means that I can't monitor any longer, doesn't it? Can you guys show me the way out, please.
Some additional info:
DB size: 143.996GB - with wiredtiger enable.
Replication set enable.
No profiling.

No updatedExisting from getLastError in MongoLab

I am running updates against a database in MongoLab (Heroku) and cannot get information from getLastError.
As an example, below are statements to update a collection in a MongoDB database running locally in my machine (db version v2.0.3-rc1).
ariels-MacBook:mongodb ariel$ mongo
MongoDB shell version: 2.0.3-rc1
connecting to: test
> db.mycoll.insert({'key': '1','data': 'somevalue'});
> db.mycoll.find();
{ "_id" : ObjectId("505bcc5783cdc9e90ffcddd8"), "key" : "1", "data" : "somevalue" }
> db.mycoll.update({'key': '1'},{$set: {'data': 'anothervalue'}});
> db.runCommand('getlasterror');
{
"updatedExisting" : true,
"n" : 1,
"connectionId" : 4,
"err" : null,
"ok" : 1
}
>
All is well locally.
Now I switch to a database in MongoLab and run the same statements to update a document. getLastError is not returning an updatedExisting field. Hence, I am unable to test if my update was successful or otherwise.
ariels-MacBook:mongodb ariel$ mongo ds0000000.mongolab.com:00000/heroku_app00000 -u someuser -p somepassword
MongoDB shell version: 2.0.3-rc1
connecting to: ds000000.mongolab.com:00000/heroku_app00000
> db.mycoll.insert({'key': '1','data': 'somevalue'});
> db.mycoll.find();
{ "_id" : ObjectId("505bcf9b2421140a6b8490dd"), "key" : "1", "data" : "somevalue" }
> db.mycoll.update({'key': '1'},{$set: {'data': 'anothervalue'}});
> db.runCommand('getlasterror');
{
"n" : 0,
"lastOp" : NumberLong("5790450143685771265"),
"connectionId" : 1097505,
"err" : null,
"ok" : 1
}
> db.mycoll.find();
{ "_id" : ObjectId("505bcf9b2421140a6b8490dd"), "data" : "anothervalue", "key" : "1" }
>
Did anyone run into this?
If it matters, my resource at MongoLab is running mongod v2.0.7 (my shell is 2.0.3).
Not exactly sure what I am missing.
I am waiting to hear from their support (I will post here when I hear back) but wanted to check with you fine folks here as well just in case.
Thank you.
This looks to be a limitation of not having admin privileges to the mongod process. You might file a ticket with 10gen as it doesn't seem like a necessary limitation.
When I run Mongo in auth mode on my laptop I need to authenticate as a user in the admin database in order to see an "n" other than 0 or the "updatedExisting" field. When I authenticate as a user in any other database I get similar results to what you're seeing in MongoLab production.
(Full disclosure: I work for MongoLab. As a side note, I don't see the support ticket you mention in our system. We'd be happy to work with you directly if you'd like. You can reach us at support#mongolab.com or http://support.mongolab.com)