Tag Archives: MongoDB

Failed to set up listener: socketexception: address already in use

error log

2018-06-08T22:25:09.118+0800 E STORAGE  [initandlisten] Failed to set up listener: SocketException: Address already in use
2018-06-08T22:25:09.118+0800 I CONTROL  [initandlisten] now exiting
2018-06-08T22:25:09.118+0800 I CONTROL  [initandlisten] shutting down with code:48

error cause

error, error log has been clear, ‘Address already in use’ has a process has been running in the port. So we’re going to find this process and turn it off.

PID(Process Identification) operating system refers to the Process Identification number. Each time the operating system opens a program, it creates a process ID, or PID. Each process has a unique PID number, which is assigned by the process runtime system and does not represent a dedicated process. The PID does not change the identifier at run time, but after the process terminates the PID identifier is retrieved by the system and may be assigned to the newly run program.

solution

find the PID number that was run before mongo, turn it off, and re-enter the start command

songrenqingdeMacBook-Pro:bin songrenqing$ lsof -i :27017
COMMAND   PID        USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
mongod  61316 songrenqing   11u  IPv4 0xacda8b230bc07883      0t0  TCP localhost:27017 (LISTEN)
songrenqingdeMacBook-Pro:bin songrenqing$ kill -9 61316

or use another process ID, previously 27017, now specify 27018, so there will be no conflict

mongod --port 27018

Mongodb failed to start: child process failed, exited with error number 100

the original link not directing a start: the child process failed, exited with the error number 100

http://f.dataguru.cn/thread-107361-1-1.html (reference: refined into gold)

today when I was at the start the mongo, find don’t come, since an error: child process failed, exited with the error number 100 and then go to/var/log/mongo/mongod log view startup log, found:

**************

Unclean shutdown detected.

Please visit
http://dochub.mongodb.org/core/repair for recovery instructions.

*************

Sat Apr 20 09:40:31.286 [initandlisten] exception in initandlisten: 12596 old lock file, terminating

seems to be caused by not closing mongodb properly. Take a look at the link and launch it as a fix.



first delete the mongod. Lock under /var/lib/mongo



and then start in repair mode:



and then again at startup



you can now see that the mongod process exists and is working properly

then how to close mongodb normally?

can go to the official documents:

http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/

connect to the server through shell first:

mongo

use admin

db.shutdownServer()

or kill -15 < pid> , note that kill -9 can cause data file corruption

error:Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused;error:couldn‘t ….

error : MongoDB shell version: 2.6.10
connecting connecting to: test
2020-01-06T19:04:40.945+0800 warning: Failed to connect to 127.0.0.1:27017, reason: Errno :111 Connection union 40
2020-01-06 t19:04:40. 946+0800 Error: Couldn ‘t connect to server 127.0.0.1:27017 (127.0.0.1), the connection attempt failed at the SRC/mongo/shell/mongo. Js: 146
I am under a virtual machine, download the mongo, want to get into mongo library, found an error (above), the Internet a lot, according to their way to try many, but is not go, Later, I found that because I did not enter into the docker image (just started to contact the image)
, I learned
from docker image , and learned

by virtue of virtual machine

step 1 , switch to su root, check all images under docker images

step 2 , if no mongo, pull mongo through docker pull mongo official website, if you have pulled direct operation step 3

step 3 0, Start container docker run-dit –name mymongodb-p 27017:27017 mongo



step 4 , open container docker exec-it mymongodb bash, enter mongo
appear the pattern in the blue circle, indicating that you have entered mongo, directly enter the command statement to operate

MongoDB Error: Failed to start mongod.service: Unit mongodb.service is masked

Reference:

reference: http://club.verimake.com/topics/36 http://stackoverflow.com/questions/37014186/running-mongodb-on-ubuntu-16-04-lts

on MongoDB: Failed to start mongod. Service: Unit MongoDB. Service is masked, you can follow the following steps:
opens the following file:

sudo vim /etc/systemd/system/mongodb.service

Paste the following into the file and save

[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target

[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

[Install]
WantedBy=multi-user.target

execute the following command:

sudo systemctl enable mongod.service
sudo systemctl daemon-reload
sudo service mongod start

Error in Python connection to mongodb pymongo.errors.OperationFailure : Authentication failed.

python connected mongo, appear pymongo. Errors. OperationFailure: Authentication failed. Error because authentication rights were not granted.
the initial join script is:


import pymongo
myclient = pymongo.MongoClient("mongodb//root:[email protected] :10000/")  xx.xx.xx.xx 是数据库服务器  root是数据库的用户名,123456是数据库的密码
mydb = myclient["test-db"]       #test-db是数据库名称 
mycol = mydb["cust_refund"]    #cust_refund是数据库的中一个数据表
for x in mycol.find({"Id":"80","testId":"1375"}):
  print(x)  

at first glance, as if that’s right, but using the statement above, at runtime, an error:
pymongo. Errors. OperationFailure: Authentication failed.

is viewed because authentication rights have not been granted.

At this point, add authenticate() function to authenticate as follows:

import pymongo
myclient = pymongo.MongoClient("mongodb://xx.xx.xx.xx :10000/")  xx.xx.xx.xx  是数据库服务器
mydb = myclient["test-db"]       #test-db是数据库名称 
mydb.authenticate('root','123456')
mycol = mydb["cust_refund"]    #cust_refund是数据库的中一个数据表
for x in mycol.find({"Id":"80","testId":"1375"}):
  print(x)  

so, once again, you can open the database.

more test communication, you can add friends

MongoDB:Failed: error connecting to db server: no reachable servers

when using mongoimport and other tools to connect to remote mongodb server, the following error is often reported:

Failed: error connecting to db server: no reachable servers

this is due to the mongodb server restriction that only allows 127.0.0.1 access. There are three modification methods:

1. Add parameter –bind_ip_all

mongod –bind_ip_all

2. Add parameters –bind_ip 0.0.0.0

mongod – bind_ip 0.0.0.0

3. Modify mongod. CFG

bindIp: 0.0.0.0

reference document

mongodb meet error: no reachable servers

Failed: error connecting to db server: server returned error on SASL authentication step: Authentica

mongdb database can not be backed up after adding user name and password, it has been suggested that the verification failed. Finally found that their database password with a special character reason.

Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.

The solution given on

network is to add — authenticationDatabase, but I still can’t add it.

~ $ mongodump -h 127.0.0.1 --port 27017 --authenticationDatabase manager -u LorettaLei -p LorettaLei$001 -o db        

2019-11-26T16:30:21.206+0800    Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.

finally figured out that it might be because I had a special character in my password. I put a backslash before the special character, and it succeeded immediately. I was so clever!

MongoDB Error: Query failed with error code 2 and error message ‘Field ‘locale’ is invalid

is a very bad exception:

2020-06-29 18:44:40.940 ERROR 15164 --- [nio-9002-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.mongodb.UncategorizedMongoDbException: Query failed with error code 2 and error message 'Field 'locale' is invalid in: { locale: "user" }' on server 192.168.10.105:27017; nested exception is com.mongodb.MongoQueryException: Query failed with error code 2 and error message 'Field 'locale' is invalid in: { locale: "user" }' on server 192.168.10.105:27017] with root cause

com.mongodb.MongoQueryException: Query failed with error code 2 and error message 'Field 'locale' is invalid in: { locale: "user" }' on server 192.168.10.105:27017
	at com.mongodb.internal.operation.FindOperation$1.call(FindOperation.java:635) ~[mongodb-driver-core-4.0.4.jar:na]
	at com.mongodb.internal.operation.FindOperation$1.call(FindOperation.java:625) ~[mongodb-driver-core-4.0.4.jar:na]
	at com.mongodb.internal.operation.OperationHelper.withReadConnectionSource(OperationHelper.java:462) ~[mongodb-driver-core-4.0.4.jar:na]
	at com.mongodb.internal.operation.FindOperation.execute(FindOperation.java:625) ~[mongodb-driver-core-4.0.4.jar:na]
	at com.mongodb.internal.operation.FindOperation.execute(FindOperation.java:77) ~[mongodb-driver-core-4.0.4.jar:na]
	at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:190) ~[mongodb-driver-sync-4.0.4.jar:na]
	at com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:135) ~[mongodb-driver-sync-4.0.4.jar:na]
	at com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:92) ~[mongodb-driver-sync-4.0.4.jar:na]
	at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:2771) ~[spring-data-mongodb-3.0.1.RELEASE.jar:3.0.1.RELEASE]
	at org.springframework.data.mongodb.core.MongoTemplate.findAll(MongoTemplate.java:1757) ~[spring-data-mongodb-3.0.1.RELEASE.jar:3.0.1.RELEASE]
	at org.springframework.data.mongodb.core.MongoTemplate.findAll(MongoTemplate.java:1752) ~[spring-data-mongodb-3.0.1.RELEASE.jar:3.0.1.RELEASE]
	at com.coldlight.mongo.service.impl.UserServiceImpl.getAllUser(UserServiceImpl.java:36) ~[classes/:na]
	at com.coldlight.mongo.controller.UserController.getAllUser(UserController.java:28) ~[classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_251]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_251]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_251]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_251]
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_251]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_251]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_251]

I did not change anything, just added a comment, suddenly error, why and the network said different, then take a closer look at the blog, my own problem, here first explain the problem

I misannotated

//正确的
@Document(collection  = "user")

is written as

//导致错误的
@Document(collation  = "user")

collection and collation are not the same.