Tag Archives: MongoDB

Mongodb Crash Error: Too many open files [How to Solve]

Problem analysis of mongodb crash error too many open files

during the actual use of the project, the customer reported that he could open the web page but could not log in. He felt that the database server should hang up for the first time, so he checked the mongodb database server log, and sure enough, it hung up. The error information is as follows:

2020-12-28T13:21:21.731+0800 E STORAGE  [conn2624] WiredTiger error (24) [1609132881:731616][23581:0x7fe157189700], WT_SESSION.create: __posix_directory_sync, 151: /data1/mongodb/data/db/collection-1063-1706476241051221735.wt: directory-sync: Too many open files Raw: [1609132881:731616][23581:0x7fe157189700], WT_SESSION.create: __posix_directory_sync, 151: /data1/mongodb/data/db/collection-1063-1706476241051221735.wt: directory-sync: Too many open files

Cause of problem:

The number of open files on the system has reached the maximum
The reason for the above problem is that Centos7 gives each user a default number of files to open at the same time of 1024, which can be checked with the ulitme -u command

Problem solving:

1. Modify the limits.conf default parameters and add the following under the file.
* soft nofile 65536
* hard nofile 65536
PS: After saving as above, you need to reboot the system to take effect permanently

2, dynamic modification (no need to restart the system and mongo)
2.1, check the mongodb service pid file
        ps aux | grep mongo
2.2、After getting the pid file, check the corresponding pid limits, the following command
        cat /proc/95051/limits
2.3、Run the following command to achieve dynamic changes
        prlimit --pid 95051 --nofile=65535:65535
2.4. Check again, the modification is successful

proposal

It is recommended that new servers first change the system default parameters

[Solved] Linux Mongodb Error: # Error: coul-bash: connecting: command not found

1. MongoDB error content and solution
This is an error when entering mongo startup

[[email protected] mongodb]# Error: coul-bash: connecting: command not found
.1:27017 :: caused by :: Connection refused :ction attempt failed: SocketException: Error connecting to 127.0.0
[1]+ Exit 127 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled
[email protected]/mongo/shell/mongo.js:374:17
@(connect):2:6
exception: connect failed
exiting with code 1
Change the permission of .sock file.

Next, we check the error report of the MongoDB log

"ctx":"SignalHandler","msg":"Shutdown: going to close listening sockets"}
{"t":{"$date":"2021-11-14T21:50:59.901+08:00"},"s":"I",  "c":"NETWORK",  "id":23017,   "ctx":"listener","msg":"removing socket file","attr":{"path":"/tmp/mongodb-27017.sock"}}
{"t":{"$date":"2021-11-14T21:50:59.901+08:00"},"s":"I",  "c":"NETWORK",  "id":4784905, "ctx":"SignalHandler","msg":"Shutting down the global connection pool"}

Solution:

The above log has said to remove mongodb-27017.sock in the/tmp directory
here, you can switch to the TMP directory to view the mongodb-xxx.sock file
remove the mongodb-27017.sock file, and then restart OK successfully
if you have tried to switch ports, remove all mongodb-xxx.sock files

[Solved] Mac Install mongodb error: NonExistentPath: Data directory /data/db not found.

Error Messages:

{“t”:{“$date”:“2021-11-10T08:18:57.122+08:00”},“s”:“E”, “c”:“CONTROL”, “id”:20557, “ctx”:“initandlisten”,“msg”:“DBException in initAndListen, terminating”,“attr”:{“error”:“NonExistentPath: Data directory /data/db not found. Create the missing directory or specify another path using (1) the –dbpath command line option, or (2) by adding the ‘storage.dbPath’ option in the configuration file.”}}
NonExistentPath: Data directory /data/db not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file.
This error means: The /data/db directory is not found. Let us use –dbpath to specify the directory to start or add storage.dbPath to specify the directory

Use --dbpath to Startup

Error report of mongodb startup under Linux

Version:MongoDB 5.0.3

1. Use the configuration file to start the error 1:

View log:

  The reason is an error in the configuration file:

#mongod.conf

net:

        bindIp: localhost,172.20.10.9         # 172.20.10.9 LAN IP for host computer

After 172.20.10.9 of bindip is deleted, it can be started successfully, but the host cannot connect to mongodb. At this time, by changing bindip to bindipall: true, it means that all IPS are allowed to connect to this mongodb

If you want to configure multiple IP addresses but do not want all IP addresses to be accessible, the above instructions are used, and the partition cannot be started. Query the network and learn that it is configured through [IP1, IP2], and the result is also an error:

Conclusion:       If it is only accessed locally, you can configure localhost in bindip,

                 If other IPS want to access, they can only configure bindip: 0.0.0.0 or bindipall: true

2. Use the configuration file to start error 2:

Problem cause: caused by abnormal shutdown

Solution: delete the. Lock file under the data directory, and then specify the data directory to start by — dbpaht or add the — repair parameter. After successful startup, start it by using the configuration file method

3. Add in replica set   No response when arbitrating nodes

Problem: by executing the shell in the master node, rs.addarb (host: port) does not respond, and the arbitration node cannot be added. At this time, the version is 5.0.3

Solution: reduce the version to 4.0.1

Robo3T Remote Connect MongoDB Error: Failed to refresh ‘Collections‘. Error: ListCollections failed

First, set up the remote connection of Mongo server:

vim  /usr/local/mongodb/etc/mongodb.conf

Note out:

bindIp: 127.0.0.1  # Listen to local interface only, comment to listen on all interfaces.

The binding IP is 127.0.0.1 by default. Only local connections are allowed

bind_ip = 0.0.0.0

Restart Mongo remote connection:

service mongod restart

Robo3T reports error connecting to remote MongoDB: Failed to refresh ‘Collections’. Error: ListCollections failed:
Possible version issue.
Robo 3T 1.4 -> MongoDB 4.2
Robo 3T 1.3 -> MongoDB 4.0
Robo 3T 1.1 -> MongoDB 3.4
Robo 3T 0.9 -> MongoDB 3.2
Robo 3T 0.8.x -> MongoDB 2.4.0
Download the corresponding version.
https://github.com/Studio3T/robomongo/releases/tag/v1.3.1

Mongodb std::exception::what(): basic_filebuf::underflow error reading the file: iostream error

Error Message:
2021-08-30T21:37:47.238+0800 F – [main] terminate() called. An exception is active; attempting to gather more information
2021-08-30T21:37:47.258+0800 F – [main] std::exception::what(): basic_filebuf::underflow error reading the file: iostream error
Actual exception type: std::__ios_failure

Solution:
Check whether the keyfile file path is correctly configured

[Solved] Mongo Error: cant post the change to mongodb there is transaction error

Mongo database
Edit, add data error:
can post the change to mongodb there is transaction error

submit transaction error:

add set error in query:

prompt: not master

Reason:
the slave node used in Mongo master-slave only has read permission by default, and the slave node connected by itself
solution:
setting in Mongo allows the slave node to be writable, or directly connects to the IP address of the master node

[Solved] org.mongodb.driver.cluster – Exception in monitor thread while connecting to server node1:27017

spring   An error was reported when the boot project started to connect mongodb.

2021-06-09 17:10:34,663 INFO  org.mongodb.driver.cluster - Exception in monitor thread while connecting to server node1:27017
com.mongodb.MongoSocketException: node1
	at com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:211)
	at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:75)
	at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65)
	at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128)
	at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.UnknownHostException: node1
	at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
	at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
	at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
	at java.net.InetAddress.getAllByName0(InetAddress.java:1276)
	at java.net.InetAddress.getAllByName(InetAddress.java:1192)
	at java.net.InetAddress.getAllByName(InetAddress.java:1126)
	at com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:203)
	... 5 common frames omitted

Because it’s a new project, Mongo library belongs to other projects. This is just a test application. So the first doubt is that the project version driver is not compatible with mongodb library. After replacing other versions of mongodb library, it is OK.

Detailed explanation

View the

<dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-mongodb</artifactId>
        <version>2.1.3.RELEASE</version>
    </dependency>

Because of spring   Mongodb driver is also the official driver of encapsulated mongodb. When you enter the spring data mongodb project, you can see that the official version of mongodb driver is 3.8.2

Then go to the official website of mongodb to see that version 3.8 supports version 4.0 database at most. I started testing with the 4.2 library (Official website https://docs.mongodb.com/drivers/java/)

So that’s it.

Mongoose Error: e11000 duplicate key error collection, code: 11000

Problem description:

MongoError: E11000 duplicate key error collection: test.elementusers index: username_1 dup key: { username: "admin" }
    at Function.create (/Users/liangrumeng/Documents/HBuilderProjects/workspace/myapp/node_modules/mongodb/lib/core/error.js:44:12)
    at toError (/Users/liangrumeng/Documents/HBuilderProjects/workspace/myapp/node_modules/mongodb/lib/utils.js:150:22)
    at coll.s.topology.insert (/Users/liangrumeng/Documents/HBuilderProjects/workspace/myapp/node_modules/mongodb/lib/operations/common_functions.js:266:39)
    at handler (/Users/liangrumeng/Documents/HBuilderProjects/workspace/myapp/node_modules/mongodb/lib/core/sdam/topology.js:1000:24)
    at wireProtocol.(anonymous function) (/Users/liangrumeng/Documents/HBuilderProjects/workspace/myapp/node_modules/mongodb/lib/core/sdam/server.js:457:5)
    at /Users/liangrumeng/Documents/HBuilderProjects/workspace/myapp/node_modules/mongodb/lib/core/connection/pool.js:408:18
    at process._tickCallback (internal/process/next_tick.js:61:11)
  driver: true,
  name: 'MongoError',
  index: 0,
  code: 11000,
  keyPattern: { username: 1 },
  keyValue: { username: 'admin' },
  errmsg:
   'E11000 duplicate key error collection: test.elementusers index: username_1 dup key: { username: "admin" }',
  [Symbol(mongoErrorContextSymbol)]: {} 

MongoError: E11000 duplicate key error collection: test.elementusers index: username_1 dup key: {username: “admin”}
at Function. Create
driver: true,
name: ‘MongoError’,
index: 0,
code: 11000,
keyPattern: {username: 1},
keyValue: {username: ‘admin’},
errmsg:
‘E11000 duplicate key error collection: Test.elementusers index: username_1 dup key: {username: “admin”}’,
[Symbol(mongoErrorContextSymbol)]: {}
The reason:
Because unique:true is set in the Schema, the registered user name must be unique.

We can make a corresponding judgment in ERR.

if(err.code == '11000'){
    res.json({
        msg:'This username has already been registered, please change your username',
        success:false
    })
}