Tag Archives: MongoDB

[Solved] Error:couldn‘t connect to server 127.0.0.1:27017, connection attempt failed: SocketException: …

Error:couldn‘t connect to server 127.0.0.1:27017, connection attempt failed: SocketException: …

Problem Examples

Do you encounter the following problems when entering mongo at the terminal?

couldn’t connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: ���� Ŀ ����������� ܾ ���� ޷ ���� ӡ �

Problem analysis

In fact, this problem is not complicated, just because your mongodb is not started. Just start it.

Problem-solving

Enter the bin directory of mongodb (enter the bin directory of mongodb you installed)

Input command (port number can be specified)

mongod –logpath “E:\professional_software\mongodb\data\log\mongodb.log” –dbpath “E:\professional_software\mongodb\data\db” –logappend

or

mongod –logpath “E:\professional_software\mongodb\data\log\mongodb.log” –dbpath “E:\professional_software\mongodb\data\db” –logappend –port 8888

In this way, the startup is successful and the next step is ready. Open another command prompt and enter mongo.

[Solved] mongod: error while loading shared libraries: libcrypto.so.1.1: cannot open shared object file: No s

After mongodb is installed, mongod reports the following error:

mongod: error while loading shared libraries: libcrypto.so.1.1: cannot open shared object file: No such file or directory

Solution:

# Switch to the lib directory
cd ~/.conda/envs/my_gdal/lib # my_gdal:virtual environment
# Check if the file exists
ls -lh | grep "libcrypto.so.1.1"
-rwxrwxrwx 1 root root 3.2M Jun 4 15:43 libcrypto.so.1.1
# If the file exists execute
sudo ldconfig ~/.conda/envs/my_gdal/lib
# If the file does not exist
sudo find/-name 'libcrypto.so.1.1'
# Execute: sudo ldconfig path found
sudo ldconfig ~/.conda/pkgs/openssl-1.1.1q-h7f8727e_0/lib/

How to Solve SpringBoot MongoDB MongoAutoConfiguration Startup Error

Background


SpringBoot project needs to manually control whether to load MongoDB auto-configuration (i.e.: MongoAutoConfiguration), then startup error

- Bean method 'mongoTemplate' in 'MongoDatabaseFactoryDependentConfiguration' not loaded because @ConditionalOnBean (types: org.springframework.data.mongodb.MongoDatabaseFactory; SearchStrategy: all) did not find any beans of type org.springframework.data.mongodb.MongoDatabaseFactory

code:

@Import(value = {MongoDataAutoConfiguration.class, MongoAutoConfiguration.class})

Solution: Replace @Import content order, load MongoAutoConfiguration first

@Import(value = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})

[Solved] ERROR: child process failed, exited with error number 100To see additional information in this …

The error below occurs when mongodb is started. Check the log file and find:

exception in initAndListen std::exception: listen: Address already in use, terminating,

 

Possible errors:

1. Your conf file is incorrectly written, format or code, etc

2. Bindip binds both the localhost and the internal and external addresses of the server

Solution: check and write the file format, and pay attention to yaml format. Then, bindip directly accesses 0.0.0.0, allowing all access. It should be OK.

If viewing the log is this error:

Failed to set up listener: SocketException: Address already in use

ps aux | grep mongod
sudo kill -9 {port-number}

[Solved] mongodump Error: assertion: 2 { ok: 0.0, errmsg: “Auth mechanism not specified”, code: 2, codeName: “BadValue”…

Mongodump error

assertion: 2 { ok: 0.0, errmsg: “Auth mechanism not specified”, code: 2, codeName: “BadValue”, operationTime: Timestamp 1573815888000|1, $clusterTime: { clusterTime: Timestamp 1573815888000|1,

reason

It is caused by the lower version of mongodump. You need to uninstall the default Yum source installation version and reinstall the new version.

System default installation version: 2. X
requirement Version (support cluster version): 4. X

terms of settlement:

create a file

/etc/yum.repos.d/mongodb-org-4.0.repo

[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc

Installation configuration

yum install -y mongodb-org

[Solved] MongoDB Update User Error: Error: not authorized on admin to execute command

MongoDB Update User Error: Error: not authorized on admin to execute command

background

The thing is this: MongoDB weak password vulnerability and high risk, the password must be changed!
Environment: windows, the database is open authentication

report errors

Log in to the database and execute:

use admin
db.changeUserPassword('admin','123456');

report errors:

[Error] Error: not authorized on admin to execute command

Solution:

1. Close mongodb service (Windows service, registered)
2. Start the service without identity authentication:

mongod --dbpath=dbpath

3. Open new CMD

mongo
use admin
db.changeUserPassword('admin','123456');

Normal
4. Restart mongodb service

[Solved] eggjs Error: Warning: Current Server Discovery and Monitoring engine is deprecated, and will be rem…

eggjs error: Warning: Current Server Discovery and Monitoring engine is deprecated, and will be rem…

Errors are reported as follows:

Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor

 

 

Cause of error reporting:

Mongoose the old parser is going to be discarded and the new parser should be used

Solution:

Add a configuration in the directory config/config.default.js:

	config.mongoose = {
	    url: 'mongodb://127.0.0.1:27017/userLog',
      options: {
         useUnifiedTopology:true
      },
	};

[Solved] MongoDB Error: Command failed with error 251 (NoSuchTransaction)

Recently, I encountered an online bug. Accessing a specific interface will cause occasional exceptions. After checking the log, it is found that an error is reported during the operation of mongodb. The error information is as follows:

error message: Command failed with error 251 (NoSuchTransaction): 'Given transaction number 115 does not match any in-progress transactions. The active transaction number is 114' on server xx.xx.xx.xx:xxxx. The full response is {"errorLabels": ["TransientTransactionError"], "ok": 0.0, "errmsg": "Given transaction number 115 does not match any in-progress transactions. The active transaction number is 114", "code": 251, "codeName": "NoSuchTransaction"}

Through searching and troubleshooting, the problem was located to be due to processing MongoDB operations where two requests in the same transaction are sent to the DB at the same time, with the probability of generating the following scenario.

1. request 1 and request 2 are sent to Mongo at the same time and start execution
2. Request 1 is still executing and request 2 has completed
3. Since request 1 is not yet completed, the transaction has not really started at DB level, so request 2 cannot end normally (that is why the error states that transaction id 115 cannot be found, because the transaction is not yet registered in DB), resulting in transaction rollback and throwing exceptions
4. request 1 execution is complete, but the transaction has been rolled back, the operation is invalid
Reviewing the code, we found that the reason why two requests are sent to DB at the same time is that the zipWith() method is used for data merging. The feature of this method is that it will request two data to be merged to the database at the same time, which will trigger the aforementioned problem when operating Mongo.

The solution is very simple, just use the zipWhen() method instead. zipWhen will block and wait for the first data requested to arrive before requesting the second data, which perfectly circumvents this problem.

[Solved] Yapi Secondary deploy error: xxx validation failed: mock: Path `xxx` is required

Previously on

Although the mongodb server declares that this field can be stored
and the front-end page also carries the parameter
when sending a request like the node service, it cannot be stored in the database and an error is reported

Error prompt

When the server reports an error

adv_source_mock validation failed: mock: Path `mock` is required.
数据表名称                                                 字段

Cause of error

I personally understand that the “mock” field is not declared in the node service
so the node service will not store the path without this field in the database and report an error
or he doesn’t know where it exists

Solution:

You can solve this problem by declaring line 92 of this field in data

How to fix the ERROR: Failed to build gem native extension in Centos 8

[root@DBAMAXWELL ~]# gem install mongo

Building native extensions. This could take a while...
ERROR:  Error installing mongo:
        ERROR: Failed to build gem native extension.

    current directory: /usr/local/share/gems/gems/bson-4.14.1/ext/bson
/usr/bin/ruby -r ./siteconf20220325-427526-vfnj46.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/share/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /usr/local/share/gems/gems/bson-4.14.1 for inspection.
Results logged to /usr/local/lib64/gems/ruby/bson-4.14.1/gem_make.out

 

Solution:
[root@DBAMAXWELL ~]# yum install ruby-devel

Last metadata expiration check: 1:48:48 ago on Fri 25 Mar 2022 05:54:43 PM CST.
Dependencies resolved.
===============================================================================================================================================================================================================
 Package                                     Architecture                            Version                                                                  Repository                                  Size
===============================================================================================================================================================================================================
Installing:
 ruby-devel                                  x86_64                                  2.5.9-109.module_el8.5.0+1097+b05a0601                                   appstream                                  126 k

Transaction Summary
===============================================================================================================================================================================================================
Install  1 Package

Total download size: 126 k
Installed size: 294 k
Is this ok [y/N]: y
Downloading Packages:
[MIRROR] ruby-devel-2.5.9-109.module_el8.5.0+1097+b05a0601.x86_64.rpm: Curl error (28): Timeout was reached for http://centosg9.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/ruby-devel-2.5.9-109.module_el8.5.0%2b1097%2bb05a0601.x86_64.rpm [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
ruby-devel-2.5.9-109.module_el8.5.0+1097+b05a0601.x86_64.rpm                                                                                                                   1.6 kB/s | 126 kB     01:17    
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                          1.6 kB/s | 126 kB     01:18     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                       1/1 
  Installing       : ruby-devel-2.5.9-109.module_el8.5.0+1097+b05a0601.x86_64                                                                                                                              1/1 
  Running scriptlet: ruby-devel-2.5.9-109.module_el8.5.0+1097+b05a0601.x86_64                                                                                                                              1/1 
  Verifying        : ruby-devel-2.5.9-109.module_el8.5.0+1097+b05a0601.x86_64                                                                                                                              1/1 

Installed:
  ruby-devel-2.5.9-109.module_el8.5.0+1097+b05a0601.x86_64

Complete!

[root@DBAMAXWELL ~]# gem install mongo
Building native extensions. This could take a while…
Successfully installed bson-4.14.1
Fetching: mongo-2.17.0.gem (100%)
Successfully installed mongo-2.17.0
2 gems installed
[root@DBAMAXWELL ~]#

[Solved] Springboot Connect MongoDB Error: UncategorizedMongoDbException: Command failed with error 13 (Unauthorized)

[phenomenon]

failed; nested exception is org.springframework.data.mongodb.UncategorizedMongoDbException: Command failed with error 13 (Unauthorized): 'command insert requires authentication' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "command insert requires authentication", "code": 13, "codeName": "Unauthorized"}; nested exception is com.mongodb.MongoCommandException: Command failed with error 13 (Unauthorized): 'command insert requires authentication' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "command insert requires authentication", "code": 13, "codeName": "Unauthorized"}] with root cause

com.mongodb.MongoCommandException: Command failed with error 13 (Unauthorized): 'command insert requires authentication' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "command insert requires authentication", "code": 13, "codeName": "Unauthorized"}
	at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:175) ~[mongodb-driver-core-4.2.3.jar:na]
	at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:358) ~[mongodb-driver-core-4.2.3.jar:na]
	at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:279) ~[mongodb-driver-core-4.2.3.jar:na]
	at com.mongodb.internal.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:100) ~[mongodb-driver-core-4.2.3.jar:na]
	at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:490) ~[mongodb-driver-core-4.2.3.jar:na]
	at com.mongodb.internal.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:71) ~[mongodb-driver-core-4.2.3.jar:na]
	at com.mongodb.internal.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:253) ~[mongodb-driver-core-4.2.3.jar:na]
	at com.mongodb.internal.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:202) ~[mongodb-driver-core-4.2.3.jar:na]
	at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:118) ~[mongodb-driver-core-4.2.3.jar:na]
	at com.mongodb.internal.operation.MixedBulkWriteOperation.executeCommand(MixedBulkWriteOperation.java:431) ~[mongodb-driver-core-4.2.3.jar:na]
	at com.mongodb.internal.operation.MixedBulkWriteOperation.executeBulkWriteBatch(MixedBulkWriteOperation.java:251) ~[mongodb-driver-core-4.2.3.jar:na]
	at com.mongodb.internal.operation.MixedBulkWriteOperation.access$700(MixedBulkWriteOperation.java:76) ~[mongodb-driver-core-4.2.3.jar:na]
	at com.mongodb.internal.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:194) ~[mongodb-driver-core-4.2.3.jar:na]
	at com.mongodb.internal.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:185) ~[mongodb-driver-core-4.2.3.jar:na]
	at com.mongodb.internal.operation.OperationHelper.withReleasableConnection(OperationHelper.java:621) ~[mongodb-driver-core-4.2.3.jar:na]
	at com.mongodb.internal.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:185) ~[mongodb-driver-core-4.2.3.jar:na]
	at com.mongodb.internal.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:76) ~[mongodb-driver-core-4.2.3.jar:na]
	at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:187) ~[mongodb-driver-sync-4.2.3.jar:na]
	at com.mongodb.client.internal.MongoCollectionImpl.executeInsertMany(MongoCollectionImpl.java:498) ~[mongodb-driver-sync-4.2.3.jar:na]
	at com.mongodb.client.internal.MongoCollectionImpl.insertMany(MongoCollectionImpl.java:480) ~[mongodb-driver-sync-4.2.3.jar:na]
	at com.mongodb.client.internal.MongoCollectionImpl.insertMany(MongoCollectionImpl.java:475) ~[mongodb-driver-sync-4.2.3.jar:na]
	at org.springframework.data.mongodb.core.MongoTemplate.lambda$insertDocumentList$17(MongoTemplate.java:1490) ~[spring-data-mongodb-3.2.6.jar:3.2.6]
	at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:553) ~[spring-data-mongodb-3.2.6.jar:3.2.6]
	at org.springframework.data.mongodb.core.MongoTemplate.insertDocumentList(MongoTemplate.java:1483) ~[spring-data-mongodb-3.2.6.jar:3.2.6]
	at org.springframework.data.mongodb.core.MongoTemplate.doInsertBatch(MongoTemplate.java:1346) ~[spring-data-mongodb-3.2.6.jar:3.2.6]
	at org.springframework.data.mongodb.core.MongoTemplate.insert(MongoTemplate.java:1280) ~[spring-data-mongodb-3.2.6.jar:3.2.6]

[solution]

Add the following configuration:

spring.data.mongodb.username=admin
spring.data.mongodb.password=admin

Modify the application.properties file as below:

spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.username=admin
spring.data.mongodb.password=admin
spring.data.mongodb.database=user

[Solved] ERROR: child process failed, exited with error number 14 (error number 1, error number 100)

Problem Description:

Error: 14 when starting mongodb, check mongodb.log for MongoDB – Unable to unlink socket file / tmp / mongodb-27017

Cause analysis:

Check /tmp/mongodb-27017.sock, found that the owner is root

Solution:

Delete the /tmp/mongodb-27017.sock file and restart the mongod process. Check the /tmp/mongodb-27017.sock permissions again and change the ownership to the “mongodb” user.

also started successfully

Summary:

1. Check more logs, mongodb.log
2. The mongodb error column, such as 1100, is mostly due to the wrong specification of the data path and log path in the configuration file. The data path needs to be created in advance, which is a directory, and the log path also needs to be created in advance, which is a file