Tag Archives: MongoDB
[Solved] C# Access Mongodb Database Error: command find failed: Command find requires authentication
The error reports are as follows:
error reason analysis:
literally means that the user name and password authentication are missing, so the database cannot be accessed
solution steps:
1 Add the user name and password to the configuration file connecting to mogondb
run the program again
over
[Solved] mongodb Install Error: mongod: error while loading shared libraries
Error:
mongodb install error: mongod: error while loading shared libraries: liblzma.so.0: cannot open shared object file: No such file or directory
Screeshots:
Solution:
1. Modify the /etc/profile file
Check the environment variables, however, no error was found
2. Modify the /etc/ld.so.conf file
1. After adding /usr/local/lib
to /etc/ld.so.conf
, I found that there is no liblzma.so.0
in this directory, only liblzma.so.5
2. At the command line, type sudo find / -name liblzma.so.0* -type f
and find that liblzma.so.0
is not found
3. Type yum install xz-compat-libs
on the command line to download liblzma.so.0
4. OK!
[Solved] mongoose Error: Error: `useCreateIndex` is an invalid option.
Error message
if (VALID_OPTIONS.indexOf(key) === -1) throw new Error(`\`${key}\` is an invalid option.`);
^
Error: `useCreateIndex` is an invalid option.
at Mongoose.set ...
Solution:
Mongoose 6 no longer needs useCreateIndex, please remove it when upgrading.
Python Connect database error: command listdatabases requires authentication
Python reports an error when connecting to the database. Command listdatabases requires authentication, full error: {OK ‘: 0.0,’ errmsg ‘:’ command listdatabases requires authentication ‘,’ code ‘: 13,’ codename ‘:’ unauthorized ‘}
The reason for the error is that authentication is required, indicating that user name and password authentication are required to connect to mongodb database.
Connect mongodb without password. The code is as follows:
from pymongo import MongoClient
class MongoDBConn:
def __init__(self, host, port, db_name, user, password):
"""
Establishing database connections
"""
self.conn = MongoClient(host, port)
self.mydb = self.conn[db_name]
With password authentication, connect to Mongo database, and the code is as follows:
from pymongo import MongoClient
class MongoDBConn:
def __init__(self, host, port, db_name, user, password):
"""
Establishing database connections
"""
self.conn = MongoClient(host, port)
self.db = self.conn.admin
self.db.authenticate(user, password)
self.mydb = self.conn[db_name]
Pit record
In fact, an error was reported in the middle:
Authentication failed., full error: {‘ok’: 0.0, ‘errmsg’: ‘Authentication failed.’, ‘code’: 18, ‘codeName’: ‘AuthenticationFailed’}
Originally used directly in the code:
self.db = self.conn[db_name]
self.db.authenticate(user, password)
If you directly use the target database for link authentication, you will report the above error. Instead, first connect to the system default database admin, use admin for authentication, and you will succeed, and then do the corresponding operation for the target database.
[Solved] mongo Startup Error: ERROR: child process failed, exited with error number 1
Because Mongo is abnormally closed, an error message of “error: child process failed, exited with error number 1” may appear when it is started again.
Step 1: delete the lock file
Find Mongo directory and delete mogod lock
Step 2: create a new log file
Find the log file directory of Mongo and delete or modify the original log file name
[because I don’t want to modify Mongo’s configuration file, I modified the file name and added a file with the same name as the original file. I can also take another name and modify Mongo configuration]
Step 3 try to restart
Generally, the restart is successful at this step.
If it still fails, take a look at Mongo’s log file
the errors reported in my log file are as follows:
2021-12-16T11:58:12.810+0800 I CONTROL [main] ***** SERVER RESTARTED *****
2021-12-16T11:58:12.815+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2021-12-16T11:58:12.820+0800 I CONTROL [main] ERROR: Cannot write pid file to /var/run/mongodb/mongod2.pid: No such file or directory
Then go to the prompt “/var/run” directory, create a new mongodb folder, and restart. Start successfully and solve the problem!
Command failed with error 16412: ‘FieldPath field names may not contain ‘.‘.‘ on server 10.21.20.8:2
- problem description
query interface error: OL>
{"errorMessage":
"Command failed with error 16412: 'FieldPath field names may not contain '.'.' on server 10.21.20.8:27019. The full response is { \"ok\" : 0.0, \"errmsg\" : \"FieldPath field names may not contain '.'.\", \"code\" : 16412, \"codeName\" : \"Location16412\" }"}
com.mongodb.MongoCommandException: Command failed with error 16412: 'FieldPath field names may not contain '.'.' on server 10.21.20.8:27019. The full response is { "ok" : 0.0, "errmsg" : "FieldPath field names may not contain '.'.", "code" : 16412, "codeName" : "Location16412" }
at com.mongodb.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:115)
at com.mongodb.connection.CommandProtocol.execute(CommandProtocol.java:114)
at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:168)
at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:289)
at com.mongodb.connection.DefaultServerConnection.command(DefaultServerConnection.java:176)
at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:216)
at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:207)
at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:113)
at com.mongodb.operation.AggregateOperation$1.call(AggregateOperation.java:257)
at com.mongodb.operation.AggregateOperation$1.call(AggregateOperation.java:253)
at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:435)
at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:408)
at com.mongodb.operation.AggregateOperation.execute(AggregateOperation.java:253)
at com.mongodb.operation.AggregateOperation.execute(AggregateOperation.java:67)
at com.mongodb.Mongo.execute(Mongo.java:836)
at com.mongodb.Mongo$2.execute(Mongo.java:823)
at com.mongodb.DBCollection.aggregate(DBCollection.java:1455)
at com.mongodb.DBCollection.aggregate(DBCollection.java:1418)
at com.mongodb.DBCollection.aggregate(DBCollection.java:1403)
at com.linkus.biz.prj.service.impl.PrjDevTaskStatServiceImpl.getPrjDevTaskStatData(PrjDevTaskStatServiceImpl.java:127)
- problem solving
check the fields in the group. The grouping fields are wrong. The value “joinbiz. Resp” of resp in the group is changed to “resp” OL>
"$group":{
"_id":{
"prjSys":"$prjSys",
"prjMod":"$prjMod",
"resp":"$_joinBiz_.resp",
},
"devTasksCount":{
"$sum":1
},
"minPlanEndDate":{
"$min":"$_joinBiz_.planEndDate"
},
"maxPlanEndData":{
"$max":"$_joinBiz_.planEndDate"
},
"planCompletionCount":{
"$sum":"$planCompletionNum"
},
"actualCompletionCount":{
"$sum":"$actualCompletionNum"
}
}
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
[root@g3dhkzznakmqafv5-1029528 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
connect@src/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
E11000 duplicate key error collection: *** index: _id_ dup key
E11000 duplicate key error collection: *** index: _id_dup key: { : “617141a3cd9d0a65d02f6c23” }
The reason is that:
assign(record, attrs);
await new VkPrize(newRecord).save();
Attrs contains the _id field, causing the same error to be reported when the _id is executed again.