Difference between revisions of "MongoDB"

From ArchWiki
Jump to: navigation, search
(MongoDB won't start: Document my boost-lib problem)
m (MongoDB won't start: it does > it is)
 
(27 intermediate revisions by 18 users not shown)
Line 1: Line 1:
 
[[Category:Database management systems]]
 
[[Category:Database management systems]]
MongoDB (from hu'''mongo'''us) is an open source document-oriented database system developed and supported by [http://www.10gen.com/ 10gen]. It is part of the NoSQL family of database systems. Instead of storing data in tables as is done in a "classical" relational database, MongoDB stores structured data as JSON-like documents with dynamic schemas (MongoDB calls the format [http://bsonspec.org/ BSON]), making the integration of data in certain types of applications easier and faster.
+
[[ja:MongoDB]]
 +
[[zh-hans:MongoDB]]
 +
MongoDB (from hu'''mongo'''us) is an open source document-oriented database system developed and supported by [http://www.mongodb.com/ MongoDB Inc. (formerly 10gen)]. It is part of the NoSQL family of database systems. Instead of storing data in tables as is done in a "classical" relational database, MongoDB stores structured data as JSON-like documents with dynamic schemas (MongoDB calls the format [http://bsonspec.org/ BSON]), making the integration of data in certain types of applications easier and faster.
  
==Installing MongoDB==
+
== Installation ==
Install {{Pkg|mongodb}}
 
# pacman -S mongodb
 
Start MongoDB
 
# systemctl start mongodb
 
(Optional) Add MongoDB to the list of daemons that start on system startup
 
# systemctl enable mongodb
 
  
==Access the database shell==
+
Install {{Pkg|mongodb}} from [[official repositories]].  You may also wish to still {{Pkg|mongodb-tools}}, which provides tools such as {{ic|mongoimport}}, {{ic|mongoexport}}, {{ic|mongodump}}, {{ic|mongorestore}}, among others.
To access the Database shell you have type in your terminal
+
 
  # mongo
+
[[Systemd#Using units|Start/Enable]] the {{ic|mongodb.service}} daemon.
 +
 
 +
During the first startup of the mongodb service, it will [https://docs.mongodb.com/manual/faq/storage/#preallocated-data-files pre-allocate space], by creating large files (for its journal and other data). This step may take a while, during which the database shell is unavailable.
 +
 
 +
== Usage ==
 +
 
 +
To access the Database shell type in the terminal:
 +
 
 +
  $ mongo
 +
 
 +
== Troubleshooting ==
 +
 
 +
=== MongoDB won't start ===
 +
 +
Check that there is at least 3GB space available for its journal files, otherwise mongodb can fail to start (without issuing a message to the user):
 +
 
 +
$ df -h /var/lib/mongodb/
 +
 
 +
Check if the mongod.lock lock file is empty or not:
  
==Troubleshooting==
 
===MongoDB won't start===
 
Check if the lock file exists
 
 
  # ls  -lisa /var/lib/mongodb
 
  # ls  -lisa /var/lib/mongodb
  
If it does, stop the mongodb service, and delete the file. Then start the service again.
+
If it is, stop {{ic|mongodb.service}}. Run a repair on the database, specifying the dbpath (/var/lib/mongodb/ is the default --dbpath in Arch Linux):
# rm /var/lib/mongodb/mongod.lock
 
  
If it still won't start, run a repair on the database, specifying the dbpath (/var/lib/mongodb/ is the default --dbpath in Arch Linux)
 
 
  # mongod --dbpath /var/lib/mongodb/ --repair
 
  # mongod --dbpath /var/lib/mongodb/ --repair
  
After running the repair as root, the files got chowned to root, whilst Arch Linux runs it under a different user. You then need to chown
+
Upon completion, the dbpath should contain the repaired data files and an empty mongod.lock file.
back the files. [http://earlz.net/view/2011/03/11/0015/mongodb-and-arch-linux Further reference]
+
 
 +
{{Warning|In dire situations, you can remove the file, start the database using the possibly corrupt files, and attempt to recover data from the database. However, it is impossible to predict the state of the database in these situations. See [https://docs.mongodb.com/manual/tutorial/recover-data-following-unexpected-shutdown/ upstream document for detail].}}
 +
 
 +
After running the repair as root, the files will be owned by the root user, whilst Arch Linux runs it under a different user. You will need to use chown to change the ownership of the files back to the correct user. See following link for further details: [http://earlz.net/view/2011/03/11/0015/mongodb-and-arch-linux Further reference]
 
   
 
   
  # cd /var/log/mongod
+
  # chown -R mongodb: /var/{log,lib}/mongodb/
# sudo chown -R mongodb:mongodb .
+
 
# cd /var/lib/mongodb
+
=== MongoDB complains about transparent_hugepage Kernel Setting ===
# sudo chown -R mongodb:mongodb .
+
 
 +
After starting the mongoDB, if you see some warnings about the transparent_hugepage you can permanently disable this System Setting by editing the following file (see [https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html FreeDesktop tmpfiles.d Manual]):
 +
 
 +
{{hc|/etc/tmpfiles.d/local.conf|<nowiki>
 +
w /sys/kernel/mm/transparent_hugepage/enabled - - - - never
 +
w /sys/kernel/mm/transparent_hugepage/defrag - - - - never
 +
</nowiki>}}
 +
 
 +
If you want to disable only for this boot, you can use SysCtl or by simply echoing in the files like below:
  
Check that the boost-libs package is up to date. MongoDB requires a specific version, however, the package does not restrict the version of this dependency.
+
# echo never > /sys/kernel/mm/transparent_hugepage/enabled
 +
# echo never > /sys/kernel/mm/transparent_hugepage/defrag

Latest revision as of 10:07, 3 August 2017

MongoDB (from humongous) is an open source document-oriented database system developed and supported by MongoDB Inc. (formerly 10gen). It is part of the NoSQL family of database systems. Instead of storing data in tables as is done in a "classical" relational database, MongoDB stores structured data as JSON-like documents with dynamic schemas (MongoDB calls the format BSON), making the integration of data in certain types of applications easier and faster.

Installation

Install mongodb from official repositories. You may also wish to still mongodb-tools, which provides tools such as mongoimport, mongoexport, mongodump, mongorestore, among others.

Start/Enable the mongodb.service daemon.

During the first startup of the mongodb service, it will pre-allocate space, by creating large files (for its journal and other data). This step may take a while, during which the database shell is unavailable.

Usage

To access the Database shell type in the terminal:

$ mongo

Troubleshooting

MongoDB won't start

Check that there is at least 3GB space available for its journal files, otherwise mongodb can fail to start (without issuing a message to the user):

$ df -h /var/lib/mongodb/

Check if the mongod.lock lock file is empty or not:

# ls  -lisa /var/lib/mongodb

If it is, stop mongodb.service. Run a repair on the database, specifying the dbpath (/var/lib/mongodb/ is the default --dbpath in Arch Linux):

# mongod --dbpath /var/lib/mongodb/ --repair

Upon completion, the dbpath should contain the repaired data files and an empty mongod.lock file.

Warning: In dire situations, you can remove the file, start the database using the possibly corrupt files, and attempt to recover data from the database. However, it is impossible to predict the state of the database in these situations. See upstream document for detail.

After running the repair as root, the files will be owned by the root user, whilst Arch Linux runs it under a different user. You will need to use chown to change the ownership of the files back to the correct user. See following link for further details: Further reference

# chown -R mongodb: /var/{log,lib}/mongodb/

MongoDB complains about transparent_hugepage Kernel Setting

After starting the mongoDB, if you see some warnings about the transparent_hugepage you can permanently disable this System Setting by editing the following file (see FreeDesktop tmpfiles.d Manual):

/etc/tmpfiles.d/local.conf
w /sys/kernel/mm/transparent_hugepage/enabled - - - - never
w /sys/kernel/mm/transparent_hugepage/defrag - - - - never

If you want to disable only for this boot, you can use SysCtl or by simply echoing in the files like below:

# echo never > /sys/kernel/mm/transparent_hugepage/enabled
# echo never > /sys/kernel/mm/transparent_hugepage/defrag