Mongos Vs Mongod Compatibility Issue - mongodb

I run a Sharded Mongo Database in Production Environment.
Recently, once of the colleagues deprecated one of the Mongos (Router) instance and the new instance was spawned up (via ASG) with a latest minor version of Mongo 4.2 which is 4.2.14. Rest of the instances (shards, mongos and configs) continue to be on 4.2.5.
Soon after this, I am facing a problem to which I can find absolutely no documentation over the web. The problem happens only for the node which has the latest version of mongos - 4.2.14.
Error - Command failed with error 40415 (Location40415): 'BSON field '$mergeCursors.recordRemoteOpWaitTime' is an unknown field.' on server 10.17.9.84:27017. The full response is {"ok": 0.0, "errmsg": "BSON field '$mergeCursors.recordRemoteOpWaitTime' is an unknown field.", "code": 40415, "codeName": "Location40415", "operationTime": {"$timestamp": {"t": 1620920773, "i": 1}}, "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1620920773, "i": 1}}, "signature": {"hash":
{"$binary": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type": "00"}
, "keyId": {"$numberLong": "0"}}}}
After a day of digging into this I could understand that from any version 4.2.5 (unknown to us at the moment) onwards all requests going out of mongos have recordRemoteOpWaitTime: true. Since rest of the nodes are lower than 4.2.13, they aren't able to recognise this attribute hence erroring out.
I cannot find any reference to this over the available documentation. I need to figure out a way to disable mongos passing this attribute to shards. Any leads would be appreciated!

Related

(Beginner) query MongoDB on DBeaver

Beginner question as I've barely started using DBeaver on querying a MongoDB.
I'd like to run a simple command like:
db.customer.find( {name: "John"} )
However, I'm getting
Command failed with error 10107 (NotMaster): 'not master' on server live-mongodb5.aws.cisha.de:27017. The full response is {"ok": 0.0, "errmsg": "not master", "code": 10107, "codeName": "NotMaster"}
I tried just db, same error. I'm unable to work out what to do next. I tried to follow https://towardsdatascience.com/8-examples-to-query-a-nosql-database-fc3dd1c9a8c to do some queries.

How do I use the Azure CosmosDB Emulator with the MongoDB API?

I use the Microsoft Azure Comos Emulator version 2.11.11.0. I start it with the command line:
CosmosDB.Emulator.exe /EnableMongoDbEndpoint=3.6
If I connect with my application to the MongoDB endpoint I receive the follow error:
com.mongodb.MongoCommandException: Command failed with error 1 (InternalError):
'[ActivityId=64bdb726-f138-4025-8d5b-ca23bbda384c] Internal error.' on server localhost:10255.
The full response is {"ok": 0.0, "errmsg": "[ActivityId=64bdb726-f138-4025-8d5b-ca23
bbda384c] Internal error.", "code": 1, "codeName": "InternalError"}
What this error means? What I need to do else to use the MongoDB API?
Failing ist the first write command:
'{"createIndexes": "fs.files", "indexes": [{"key": {"filename": 1}, "name": "filename_1", "ns": "admin.fs.files"}], "$db": "admin", "lsid": {"id": {"$binary": {"base64": "lFHKYPJ0Rq+ip587pl8YPQ==", "subType": "04"}}}, "$readPreference": {"mode
": "primaryPreferred"}}'
It was produces from the simple Java line:
collection.createIndex( new BasicDBObject( FILENAME, 1 ) );
PS: With MongoDb endpoint 3.2 this is working. It must be any problem with the emulator.
With the emulator Mongo API 3.6 there must be created the collection explicit. With the original MongoDB and the Mongo API end point 3.2 the collection will be indirect created if a Index is created or data are saved.

Query a stored procedure in mongodb using spring boot

I want to query a stored procedure in mongodb. I can query it using the command line tool but facing issue while querying using java.The piece of code(last two lines) that is throwing error is :
MongoClient mongoClient = new MongoClient();
MongoDatabase mdb = mongoClient.getDatabase("mydb");
mdb.runCommand(new Document("$eval", "db.loadServerScripts()"));
Document doc1 = mdb.runCommand(new Document("$eval", "mysp(5)"));
and the error that it's throwing is 'no such command: '$eval'' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "no such command: '$eval'", "code": 59, "codeName": "CommandNotFound"}
Now I read several posts and documentation as well stating that $eval or db.eval() doesn't works for mongo version 4.2. So what should I change in my code to make it work or what should be the possible solution. I know this question has been asked several times but those solutions are obsolete , so I need help for this. Can anyone help.
From mongodb-4.2, the support for the eval command is deprecated now.
So I guess the only option will be to use mongodb-4.0 as of now.
Source : https://docs.mongodb.com/manual/reference/method/db.eval/

mongodb set feature compatibility to 3.4 fail

I want to enable the features of my Mongodb 3.4 after upgrading.
I have sharded cluster enviroment
And after I ran the commands:
use admin
db.adminCommand ({setFeatureCompatibilityVersion: "3.4"})
In mongos instance
I got the following output:
{"ok": 1}
But when I try to check with it succeeded with command:
db.adminCommand ({getParameter: 1, featureCompatibilityVersion: 1})
I get the following output:
{"ok": 0, "errmsg": "no option found to get"}
And when I check in ops manager I see that the command did not work

Remote MongoDB access through Cloud 9 gives login failed exception

I'm using the Cloud 9 IDE to develop an application using MongoDB. I created a database called "appdata" at MongoLab and the following user:
{
"_id": "appdata.admin",
"user": "admin",
"db": "appdata",
"credentials": {
"SCRAM-SHA-1": {
"iterationCount": 10000,
"salt": "K/WUzUDbi3Ip4Vy59gNV7g==",
"storedKey": "9ow35+PtcOOhfuhY7Dtk7KnfYsM=",
"serverKey": "YfsOlFx1uvmP+VaBundvmVGW+3k="
}
},
"roles": [
{
"role": "dbOwner",
"db": "appdata"
}
]
}
Whenever I try connecting to the database through Cloud 9 Shell using the following command (given by MongoLab with my newly created user):
mongo ds057244.mongolab.com:57244/appdata -u admin -p admin
I get the following error message:
MongoDB shell version: 2.6.11
connecting to: ds057244.mongolab.com:57244/appdata
2015-11-22T05:23:49.015+0000 Error: 18 { ok: 0.0, errmsg: "auth failed",
code: 18 } at src/mongo/shell/db.js:1292
exception: login failed
Also, on my javascript file running on Cloud 9, while following this tutorial (which uses mongoose to access the DB) I got stuck on the post route for bears. Whenever I send a post request through postman with the specified fields set, the route doesn't return anything, neither a bear created nor an error message, which makes me think the problem is also failing to login to the database. The previous get request is working just fine and my code is the exactly same as the tutorial.
Does anyone know what the problem in any of the cases and what I need to do to solve them?
The shell problem was fixed updating it to the Database version (which was 3.0.3).
For the javascript files, I restarted the tutorial and made sure I downloaded all necessary dependencies with the most recent stable version (not the ones shown on the tutorial), after that the problem was solved.