Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
db:mongodb [2014/05/19 14:48] alfred [Getting started] |
db:mongodb [2020/05/09 09:25] (actual) |
||
|---|---|---|---|
| Línea 9: | Línea 9: | ||
| $ sudo apt-get install mongodb-org | $ sudo apt-get install mongodb-org | ||
| </code> | </code> | ||
| + | |||
| + | Si en /etc/apt/sources.list.d aparece el fichero ''mongod'' sin extensión, entonces tendrás que renombrarlo a ''mongod.list''. \\ | ||
| + | Probablemente tengas que lanzar ''sudo apt-get install mongodb-server'' | ||
| === Run Mongo === | === Run Mongo === | ||
| <code> | <code> | ||
| $ sudo start mongod | $ sudo start mongod | ||
| + | </code> | ||
| + | ... or... | ||
| + | <code> | ||
| + | $ sudo service mongod start | ||
| </code> | </code> | ||
| === Stop Mongo === | === Stop Mongo === | ||
| Línea 22: | Línea 29: | ||
| </code> | </code> | ||
| - | === Useful commands in mongo console === | ||
| - | * ''help'' to display help. | ||
| - | * ''show collections'' list available collections. | ||
| === Mongo principles === | === Mongo principles === | ||
| Línea 35: | Línea 39: | ||
| * List your databases with ''show dbs'' command. | * List your databases with ''show dbs'' command. | ||
| * Create and switch to a new (newdb) data base with ''use newdb'' command. | * Create and switch to a new (newdb) data base with ''use newdb'' command. | ||
| + | * ''help'' to display help. | ||
| + | * ''show collections'' lists available collections. | ||
| + | ==== In a nutshell... ==== | ||
| + | === ... Insert data === | ||
| + | <code> | ||
| + | j = { name : "mongo" } | ||
| + | k = { x : 3 } | ||
| + | db.testData.insert( j ) | ||
| + | db.testData.insert( k ) | ||
| + | </code> | ||
| + | |||
| + | === ... List inserted data === | ||
| + | <code> | ||
| + | db.testData.find() | ||
| + | </code> | ||
| + | ==== Configuration ==== | ||
| + | === Allow external connections === | ||
| + | You should edit ''/etc/mongodb.conf'' file and change the bind_ip and port values. These would be the values: | ||
| + | <code> | ||
| + | bind_ip = 0.0.0.0 | ||
| + | port = 27017 | ||
| + | </code> | ||
| + | |||
| + | ===== Notes ===== | ||
| + | * Logs are found in ''/var/log/mongodb'' | ||
| + | * ''Robomongo'' is a good ubuntu GUI client for MongoDB. | ||
| + | |||
| + | ==== Recover MongoDB after crash ==== | ||
| + | When the system crashes MongoDB remains locked (error is shown in logs as //mongodb exception in initandlisten old lock file//). You chan do two things to unlock it: | ||
| + | * If this is a development machine, you can remove the lock file manually. It's in ''/var/lib/mongodb/mongod.lock'' or it could be named ''mongo.lock''. | ||
| + | * The safer route is to follow [[http://docs.mongodb.org/manual/tutorial/recover-data-following-unexpected-shutdown/|MongoDB's Durability and Repair guide]]. In summary, for a machine with the above configuration, you should execute the following commands: | ||
| + | <code> | ||
| + | $ sudo -u mongodb mongod --repair --dbpath /var/lib/mongodb/ | ||
| + | $ sudo service mongodb start | ||
| + | </code> | ||