Tag Archives: mongodb

[Solved] PHP connect to MongoDB error: Server does not support sessions

Solution steps:

Find the mongodb configuration file and make the following adjustments

   oplogSizeMB: <int>
   replSetName: <string>
   enableMajorityReadConcern: <boolean>

After restarting the mongodb service, enter Mongo for execution



Raspberry pie: How to Solve Mongodb installation error

Mongodb windscreens windscreens windscreens windscreens windscreens

adduser –firstuid 100 –ingroup nogroup –shell /etc/false –disabled-password –gecos "" –no-create-home mongodb
cp -R mongodb-rpi/mongo /opt
chmod +x /opt/mongo/bin/*
mkdir /var/log/mongodb
chown mongodb:nogroup /var/log/mongodb
mkdir /var/lib/mongodb
chown mongodb:nogroup /var/lib/mongodb
cp mongodb-rpi/debian/init.d /etc/init.d/mongod
cp mongodb-rpi/debian/mongodb.conf /etc/
ln -s /opt/mongo/bin/mongod /usr/bin/mongod
chmod u+x /etc/init.d/mongod
update-rc.d mongod defaults
/etc/init.d/mongod start

Common commands:

sudo service mongodb start

chack the status
sudo service mongodb status

sudo service mongodb stop

error and solution:

mongod.service – LSB: An object/document-oriented database
Loaded: loaded (/etc/init.d/mongod)
Active: active (exited) since 二 2017-07-18 19:17:07 CST; 1 day 21h ago
Process: 444 ExecStart=/etc/init.d/mongod start (code=exited, status=0/SUCCESS)


7月 18 19:17:05 raspberrypi systemd[1]: Starting LSB: An object/document-oriented database…
7月 18 19:17:07 raspberrypi mongod[444]: Starting database: mongodb.
7月 18 19:17:07 raspberrypi systemd[1]: Started LSB: An object/document-oriented database.
7月 19 09:31:42 raspberrypi systemd[1]: Started LSB: An object/document-oriented database.
7月 20 16:20:54 raspberrypi systemd[1]: Started LSB: An object/document-oriented database.

7月 20 16:22:34 raspberrypi mongod[4625]: Starting database: mongodb failed!
7月 20 16:22:34 raspberrypi systemd[1]: mongod.service: control process exited, code=exited
7月 20 16:22:34 raspberrypi systemd[1]: Failed to start LSB: An object/document-oriented dat


cd /var/lib
sudo rm -rf ./mongodb
sudo mkdir mongodb
sudo chown -R mongodb mongodb/
sudo service mongod restart

Error reported when Java connects mongodb com.mongodb.mongosocketopenexception: exception opening socket has been solved

Using idea to write java connection mongodb to report an error, let’s take a look at the detailed error information first



vim mongodb/conf/mongod.conf



After modification, the configuration file is as follows:

#Specify the start port
#Specify the data storage directory
#Specify the log storage directory
#Run in the background
#Log in with any IP

Causes of error information

Since mongodb version 3.6, it has_ The value of IP is localhost by default, so you can only use localhost to log in

Just change its IP to, you can use any IP login

Mongodb Cannot Start: child process failed, exited with error number 100

Mongodb cannot be started: child process failed, exited with error number 100

March 1, 2016 17:22:12sinat_ 30397435 reads 29511 article tag: mongodb

Mongodb: child process failed, exited with error number 100
cannot be started http://f.dataguru.cn/thread-107361-1-1.html
(source: refining numbers into gold)
Today, when starting mongodb, I found that I couldn’t get up and reported an error: child process failed, exited with error number 100 and then I went to/var/log/Mongo/mongod.log to check the startup log

Unclean shutdown detected.
Please visithttp://dochub.mongodb.org/core/repairfor Recovery instructions.
sat APR 20 09:40:31.286 [initandlisten] exception in initandlisten: 12596 old lock file, terminating

it seems that mongodb is not closed normally. According to the prompt link to see the next, to repair the way to start<

delete mongod. Lock under/var/lib/Mongo first

and then start in repair mode:

then start once

now you can see that mongod process exists and can be used normally

so how to shut down mongodb normally
you can go to the official documents:

connect to the server through shell first:
use admin
dB. Shutdown server ()

or kill – 15 < pid>, Note that kill – 9 may cause data file corruption

[Solved] MongoDB Start ERROR: child process failed, exited with error number


Error: child process failed, exited with error number

The above error was found this afternoon. The next application from GitHub down needs redis to start the service and mongodb to start the service before the application starts. Therefore, when mongodb is started, the tragedy appears


The reasons for this error are as follows:

Most of it is because mongodb is locked when it is shut down abnormally. Think about it, it may be caused by the last unexplained crash

How to solve this problem:

delete the mongod.lock file and the log file mongodb.log.2014-11-17t06-55-20, and delete all the log logs if necessary

mongod –repair –dbpath /data/db/–repairpath /tmp/mongodb




OK, mongodb started successfully


MongoDB Startup Error: Failed to connect to, reason: errno:111 Connection refused

Mongodb login failed, report

2017-08-17T16:24:04.385+0800 W NETWORK  [thread1] Failed to connect to, reason: errno:111 Connection refused
2017-08-17T16:24:04.385+0800 E QUERY    [thread1] Error: couldn't connect to server, connection attempt failed :

Such an error, and then fix it, and restart (Mongo’s path is modified by itself)

cd /usr/local/mongodb/bin
./mongod  --repair
mongod -f ../etc/mongodb.conf 

The following error was reported:

about to fork child process, waiting until server is ready for connections.
forked process: 20539
ERROR: child process failed, exited with error number 1


Delete the lock and restart (the paths vary from person to person, but they are all under Mongo’s storage path (DB))

rm /data/mongo/db/mongod.lock

Then restart it

mongod -f ../etc/mongodb.conf 

It’s OK

Unable to start mongod after installing mongodb in Ubuntu

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

I’m going to learn mongodb today. I didn’t expect that the server could not be started after downloading. I’d like to record the problems and handling process

I. installation

It’s still very easy to install in Ubuntu, direct: sudo apt install mongodb

2. Start

Start mongodb server: enter mongod (or use the sudo service mongodb start command to start the terminal in the background without blocking the terminal. Here I use the blocking terminal start mode)

An error occurred: exception in initandlisten: nonexistentpath: data directory/data/DB not found., terminating # prompt that the/data/DB folder is missing

Create folder: MKDIR – P/data/db

Start mongod again: exception in initandlisten: illegaloperation: committed to create a lock file on a read-only Directory:/data/DB, terminating # prompt that the permission of/data/DB folder is read-only

Modify folder permissions: sudo Chmod a + W/data/DB # set folder permissions to writable

When mongod is started again, there is still an error: failed to set up listener: socketexception: address already in use # indicating that the address has been occupied

Take a look at the current connection of mongodb: PS – ef|grep Mongo
mongodb 52874 10:27?00:00:05/usr/bin/mongod — unixsocketprefix =/run/mongodb — config/etc/mongodb. Conf
Horace 53796 53687 0 10:43 PTS/1 00:00:00 grep — color = auto Mongo
has been started

Then we restart once: enter mongodb client: enter Mongo
and then enter:
use admin
dB. Shutdown server ()?Close mongodb server

Try again: mongod

It’s not easy to install mongodb. I don’t know if there is a problem with my installation. That’s why there are so many problems

mongodb not authorized on admin to execute command [version 3.2.18]

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

Mongodb version 3.2.18 test questions:


Judging from the content of the error report, the authority is not enough, but I don’t know why, because the super user authority already used:

    "_id" : "admin.myUserAdmin",
    "user" : "root",
    "db" : "admin",
    "roles" : [
            "role" : "userAdminAnyDatabase",
            "db" : "admin"
            "role" : "dbOwner",
            "db" : "admin"

After the solution to the query error, it is found that the cluster management authority is insufficient. After adding the corresponding authority, the problem can be solved. The change of user authority is as follows:

            roles : 
                  {"role" : "userAdminAnyDatabase","db" : "admin"},
                  {"role" : "dbOwner","db" : "admin"},
                  {"role" : "clusterAdmin", "db": "admin"}

Successfully shut down the database system:

db.shutdownServer({shutdown: 1, force: true})


See also 38142142;
User: https://docs.mongodb.org/v3.0/reference/method/db.updateUser/
mongodb backup location: http://www.linuser.com/thread-507-1-1.html
mongodb user roles:https http://docs.mongodb.org/v3.0/reference/built-in-roles/
reward detection: http://stackoverflow.com/questions/13303685/stop-unknown-instance-mongodb-ubuntu

Mongodb’s “not master and slave = false” error and its solution

First of all this is normal because SECONDARY is not allowed to read and write. In applications with more writes and less reads, Replica Sets are used to achieve read and write separation. By specifying at connection time or specifying slaveOk in the master, the secondary shares the read pressure and the primary only takes on the write operations.

For secondary nodes in a replica set that are not readable by default, the

[mongodb@ligh bin]$ mongo

MongoDB shell version: 2.0.1

connecting to:

SECONDARY> db.user.find()

error: { “$err” : “not master and slaveok=false”, “code” : 13435 }

SECONDARY> db.getMongo()

connection to

SECONDARY> db.getMongo().setSlaveOk();

not master and slaveok=false

Set slaveok=ok on the master

[mongodb@ligh bin]$ mongo

MongoDB shell version: 2.0.1

connecting to:



Testing in the slave library

SECONDARY> db.user.find()

{ “_id” : ObjectId(“4eb68b1540643e10a0000000”), “id” : 1, “name” : “zhangsan” }

{ “_id” : ObjectId(“4eb68b1540643e10a0000001”), “id” : 2, “name” : “;lisi” }

there is another method to solve this error:

Mac Run MongoDB error: exception in initAndListen: NonExistentPath: Data directory /data/db not found., t…

this is the main error:

Exception in initandlisten: nonexistentpath: data directory /data/DB not found

Catalina, the latest version of the MAC system, has made a surprising change: it does not allow changes to the root directory (which is also discussed in the forum topic)

% sudo mkdir -p /data/db
mkdir: /data/db: Read-only file system

Unfortunately, this is not explicitly stated in Apple’s Catalina release notes, except for the brief mention in Catalina features:

MacOS Catalina runs on a dedicated read-only system volume

Since the directory /data/DB is encoded as mongodb default directory, one solution is to specify a directory where dbpath is not on the root directory. For example:

mongod --dbpath ~/data/db

This will put the mongodb data in your home directory. Just make sure that the path ~/data/DB does exist

alternative method

An alternative method is to use the instructions in installing mongodb Community Edition on MacOS brew :

brew tap mongodb/brew
brew install mongodb-community

By default, this creates some other files:

Configuration file (/ usr/local/etc/mongod. CONF)

Log directory path (/ usr/local/var/log/mongodb)

To run the data directory path (/ usr/local/var/mongodb), mongod you can:

Run the command manually from the command line (you can use an alias for convenience):

mongod --config /usr/local/etc/mongod.conf

Use to run brew services with mongodb as a service. Note that this will run mongodb as a stand-alone node (rather than a replica set), so functionality depending on oplog (such as changestream) will not work unless you modify the mongod configuration file:

brew services start mongodb-community