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

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

After restarting the mongodb service, enter Mongo for execution

rs.initiate()
    Done!

Reference:
https://stackoverflow.com/questions/50255195/how-to-configure-a-mongodb-cluster-which-supports-sessions

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:

startup
sudo service mongodb start

chack the status
sudo service mongodb status

stop
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

Solution:

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

Solutions

Editor

vim mongodb/conf/mongod.conf

Add

bind_ip=0.0.0.0

After modification, the configuration file is as follows:

#Specify the start port
port=27017
#Specify the data storage directory
dbpath=data/db
#Specify the log storage directory
logpath=log/mongodb.log
#Run in the background
fork=true
#Log in with any IP
bind_ip=0.0.0.0

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 0.0.0.0, 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:
http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/

connect to the server through shell first:
Mongo
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

zhangzhi@moke:~$mongod--dbpath=/data/club--port=27017--fork--logpath=/var/log/mongodb/mongodb.log
abouttoforkchildprocess,waitinguntilserverisreadyforconnections.
forkedprocess:43110
alloutputgoingto:/var/log/mongodb/mongodb.log
logfile[/var/log/mongodb/mongodb.log]existsandcouldn'tmakebackup[/var/log/mongodb/mongodb.log.2014-11-17T06-55-20];runwith--logappendormanuallyremovefile:errno:13Permissiondenied
Badlogpathvalue:"/var/log/mongodb/mongodb.log";terminating.
ERROR:childprocessfailed,exitedwitherrornumber1

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

root@moke:~#mongod--repair--dbpath/data/db/--repairpath/tmp/mongodb
MonNov1715:19:15.374Youmustusea--repairpaththatisasubdirectoryof--dbpathwhenusingjournaling
MonNov1715:19:15.375dbexit:
MonNov1715:19:15.375shutdown:goingtocloselisteningsockets...
MonNov1715:19:15.375shutdown:goingtoflushdiaglog...
MonNov1715:19:15.375shutdown:goingtoclosesockets...
MonNov1715:19:15.375shutdown:waitingforfspreallocator...
MonNov1715:19:15.376shutdown:lockforfinalcommit...
MonNov1715:19:15.376Assertionfailurecsrc/mongo/db/client.h235
0x1033e4d800x1033b85e70x10305cd470x10305cb1a0x10305ce970x10305e33d0x10305fd750x10312e69d0x102ef6c630x102ef26fd0x7fff8dd185c9
0mongod0x00000001033e4d80_ZN5mongo15printStackTraceERSo+64
1mongod0x00000001033b85e7_ZN5mongo12verifyFailedEPKcS1_j+295
2mongod0x000000010305cd47_ZN5mongo4Lock26ParallelBatchWriterSupport6relockEv+391
3mongod0x000000010305cb1a_ZN5mongo4Lock26ParallelBatchWriterSupportC2Ev+26
4mongod0x000000010305ce97_ZN5mongo4Lock10ScopedLockC2Ec+39
5mongod0x000000010305e33d_ZN5mongo4Lock10GlobalReadC2Ei+29
6mongod0x000000010305fd75_ZN5mongo11readlocktryC2Ei+53
7mongod0x000000010312e69d_ZN5mongo6dbexitENS_8ExitCodeEPKc+893
8mongod0x0000000102ef6c63_ZL25processCommandLineOptionsRKSt6vectorISsSaISsEE+14755
9mongod0x0000000102ef26fdmain+637
10libdyld.dylib0x00007fff8dd185c9start+1
MonNov1715:19:15.420shutdownfailedwithexception
MonNov1715:19:15.420dbexit:reallyexitingnow

mongod–dbpath=/data/db–port=27017–fork—-logpath=/val/log/mongodb/mongodb.log

root@moke:~#mongod--dbpath=/data/db--port=27017--fork--logpath=/var/log/mongodb/mongodb.log
abouttoforkchildprocess,waitinguntilserverisreadyforconnections.
forkedprocess:43144
alloutputgoingto:/var/log/mongodb/mongodb.log
logfile[/var/log/mongodb/mongodb.log]exists;copiedtotemporaryfile[/var/log/mongodb/mongodb.log.2014-11-17T07-21-41]
childprocessstartedsuccessfully,parentexiting

OK, mongodb started successfully

 

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

Mongodb login failed, report

2017-08-17T16:24:04.385+0800 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2017-08-17T16:24:04.385+0800 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, 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

Solution:

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
success

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:

Analysis:

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:

db.updateUser(
 "root",
        {
            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})

http://blog.csdn.net/warrior_zhang/article/details/50503407

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 127.0.0.1:33333

MongoDB shell version: 2.0.1

connecting to: 127.0.0.1:33333/test

SECONDARY> db.user.find()

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

SECONDARY> db.getMongo()

connection to 127.0.0.1:33333

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

not master and slaveok=false

Set slaveok=ok on the master

[mongodb@ligh bin]$ mongo 127.0.0.1:33333

MongoDB shell version: 2.0.1

connecting to: 127.0.0.1:33333/test

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

PRIMARY>

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:
http://stackoverflow.com/questions/8990158/mongdodb-replicates-and-error-err-not-master-and-slaveok-false-code

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

https://stackoverflow.com/questions/58283257/mongodb-cant-find-data-directory-after-upgrading-to-mac-os-10-15-catalina