Skip to main content
34 votes
Accepted

How to specify authentication database and target database separately on mongodb connection uri?

Yes.. Easily! mongo "mongodb://test:testpwd@localhost/test?authSource=admin" MongoDB shell version v3.4.6 connecting to: mongodb://test:testpwd@localhost/test?authSource=admin MongoDB server version: ...
JJussi's user avatar
  • 5,723
13 votes
Accepted

How to views all documents in a particular collection of database in MongoDB through mongo Shell?

OK, let's start from basics! After you have connected to mongod with command mongo. List databases with command show dbs iot:PRIMARY> show dbs admin 0.000GB iot 0.020GB local ...
JJussi's user avatar
  • 5,723
10 votes
Accepted

mongorestore Too many open files

ulimit can be set in the same terminal by ulimit -n 10000; You can change the value in /etc/security/limit.conf file by nofiles to 10000 #line the maximum no of files can be opened in any linux/...
Niraj Adhikary's user avatar
8 votes
Accepted

Mongodb Secondary Node not recovering

Link in the error message exactly explain what happened. A replica set member becomes “stale” when its replication process falls so far behind that the primary overwrites oplog entries the ...
SqlWorldWide's user avatar
  • 13.6k
7 votes
Accepted

Multiple BindIp in MongoDB 3.4.1 on Debian Jessie

Remove []. so solution is: bindIp: 127.0.0.1,192.168.20.1 and remember, no space characters anywhere in that string.
JJussi's user avatar
  • 5,723
5 votes

How to views all documents in a particular collection of database in MongoDB through mongo Shell?

Ref: https://docs.mongodb.com/manual/tutorial/query-documents/ Select All Documents in a Collection To select all documents in the collection, pass an empty document as the query filter parameter ...
SqlWorldWide's user avatar
  • 13.6k
4 votes
Accepted

Service mongod fails after adding security.keyFile in config file

Use full path for keyfile. Don't use ~ -character there. Your mongod is started (probably) with user 'mongod' and that user don't have home directory. Additionally keyfile must be have chmod 0400 and ...
JJussi's user avatar
  • 5,723
4 votes

How to specify authentication database and target database separately on mongodb connection uri?

Ref: https://docs.mongodb.com/manual/reference/connection-string/#connections-connection-options You will need to use below format and do not need to use admin database. mongodb://user:password@...
SqlWorldWide's user avatar
  • 13.6k
4 votes

MongoDB Maxing CPU Usage

Strange indeed. That local.oplog.rs is journaling what is enable (default) at 64 bit systems (32bit default value is false). So, running time for that thread should be same than your mongod uptime. ...
JJussi's user avatar
  • 5,723
4 votes

mongo crashing due to too many open files

I have gone through your error and find out that in your case the Open file limit is 990000. Which is sufficient to open the mongos and mongod process. As per MongoDB BOL Here The default net....
Md Haidar Ali Khan's user avatar
4 votes
Accepted

Save output of a Mongo Command to a Variable bash script

Mongo -command have multiple parameters that are handy in this case. '--eval' let you run commands and '--quiet' keep all clutter away out=$(mongo --quiet --eval="db.currentOp()") ; echo $...
JJussi's user avatar
  • 5,723
3 votes
Accepted

Is MongoDB IXSCAN operator a scan or a seek?

I guess MongoDB can do index seek and index scan ? Yes MongoDB can do index seek and index scan, but it can do both during one fetch. That is what happened in your case. If started with a seek to ...
SqlWorldWide's user avatar
  • 13.6k
3 votes
Accepted

Why `distinct` and `count` operations generate `"op": "command"` in system.profile

Originally, all database operation in MongoDB are encoded in the Wire Protocol. However, this would mean that creating a new command would involve: Creating a new opcode in the wire protocol, and ...
kevinadi's user avatar
  • 548
3 votes
Accepted

How to set up a user who doesn't have `admin` database access but use it as authentication database?

Not need. You just give user needed rights to the wanted non-admin database. User can use admin database as authentication database even user doesn't have read/write access to admin database. use ...
JJussi's user avatar
  • 5,723
3 votes

MongoDB secondary node does not become primary when other nodes are stopped

This is by design. If you want to run with only one node, restart that node without replica set switch. If a majority of the replica set is inaccessible or unavailable to the current primary, ...
SqlWorldWide's user avatar
  • 13.6k
3 votes

Replica Set not getting created

OK.. It's look like that you have managed to mix things. So, you have working mongodb at "C:\program files\mongodb\data" and now you want to convert that mongodb to three node replica set?!? First ...
JJussi's user avatar
  • 5,723
3 votes
Accepted

WiredTiger internal cache

Do we need to keep extra memory for some kind of memory mapped files for MongoDB data files The mem.mapped and mem.mappedWithJournal metrics in serverStatus output are only applicable to the MMAPv1 ...
Stennie's user avatar
  • 10.3k
3 votes

What's the difference between DISTINCT_SCAN and IXSCAN in explain output?

They are different stages for different purposes. I believe DISTINCT_SCAN is only present when there is an index in the field. An IXSCAN stage basically means that the query planner scans an index as ...
kevinadi's user avatar
  • 548
2 votes

Bind MongoDB to IPv4, as well as IPv6

As per MongoDB BOL Here To bind to all IPv4 addresses, enter 0.0.0.0. To bind to all IPv4 and IPv6 addresses, enter 0.0.0.0,:: or alternatively, use the net.bindIpAll setting. Note: Before you bind ...
Md Haidar Ali Khan's user avatar
2 votes

Bind MongoDB to IPv4, as well as IPv6

Did you find an answer yet? If not, here is the solution: IPv6 is disabled by default, you have to enable it for binding on IPv6. The following net-config should work: net: ipv6: true port: ...
olivergregorius's user avatar
2 votes
Accepted

Restoring the database dump of a newer version to an older version of mongodb

Assuming you aren't using any newer features or index/collection options from MongoDB 3.2+ that aren't supported in MongoDB 3.0, you should be able to restore the backup. Before doing so, I would ...
Stennie's user avatar
  • 10.3k
2 votes
Accepted

service mongod cant start, permission denied mongod.lock when changing dbpath

If you now command: sudo chown -R mongodb:mongodb /home/user/mongodb sudo service mongod restart It will work! Problems here was that you gave command sudo mongod --dbpath /home/user/mongodb/data/ ...
JJussi's user avatar
  • 5,723
2 votes
Accepted

Transferring Mongodb database with rsync while working, is it okay?

No, not directly! If your data is top of LVM, do a snapshot and copy that to another node, start it and connect it to the replica set. This only if you have lot's of data and normal initial sync (as @...
JJussi's user avatar
  • 5,723
2 votes

Issue with MongoDB Replication Set

I fixed the issue by adding below lines in /etc/mongod.conf replication: replSetName: yogi
Rakesh K's user avatar
  • 121
2 votes
Accepted

What is the behavior of null/empty value in compound shard key?

In MongoDB 'null' is just another value so two documents that have the same values for field1 (some non-null) and same value for field2 (null) have the same value for the shard key and will always be ...
Asya Kamsky's user avatar
2 votes
Accepted

MongoDb linearizable read concern restrictions

Dmitry, As of MongoDB v3.6, MongoDB only supports the linearizable read concern on single documents, hence the wording of the documentation. However, it doesn't mean you have to run the query using a ...
Raphael Londner's user avatar
2 votes

How to run mongod from the commandline?

Because nothing is written to log file, the first (and only) problem is (probably) ownership of log file. Usermongodb don't have access to that file. sudo chown -R mongodb: /var/log/mongodb should fix ...
JJussi's user avatar
  • 5,723
2 votes
Accepted

Mongodb Standalone Performs better than Replica Set

I would like to know what could be the real reason for the replica sets to function slower compared to the standalone db. Replica sets provide high availability and data redundancy, but these ...
Stennie's user avatar
  • 10.3k
2 votes

MongoDB multiple Cluster data sync

1)MongoDB - Multiple cluster data synchronizing master to master As MongoDB jira documentation Why was MongoDB not designed to have master-master replication actually, don't think master-master ...
Md Haidar Ali Khan's user avatar
2 votes

MongoDB update multiple sub documents inside array, each according to a condition

Use the arrayFilters property: db.getCollection("test").updateOne( { "wid": 1 }, { $inc: { "items.$[aa].sent": 37, "items.$[bb].sent": 58, ...
Marcos Zolnowski's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible