This is an old revision of the document!


Mongo DB

Mongo DB patri mezi nerelacni (NoSQL) natabaze, tedy databaze dvojic - (klic, hodnota). Couch DB je databaze, ktera bezi jako sluzba, tedy typu Server - Klient. Vychozi port pro Couch DB je 27017.

Externi odkazy

Inside MongoDB: the Internals of an Open-Source Database - prezentace o vnitrni architekture mongodb

Start/stop/status

service couchdb start/stop … start/stop databaze

Konfigurace

JSON, Ovladani, atd

mongo –quiet dhsreport –eval “db.getCollectionNames().join('\n')” … spusti mongo prikaz z prikazove radky
mongo “mongodb+srv:SERVER” –username USER -p $HESLO … pripojeni do interaktivniho modu
====prikazy v mongo klientovi==== use testdb … prepne se do databaze testdb, i kdyz neexituje (vytvori se prvnim zaznamem)
show dbs … seznam databazi
db.dropDatabase() … smaze databazi
show collections … seznam collection
db.createCollection(name, options) … vytvori collection
db.createCollection(“mycollection”)
db.system.namespaces.find() … jiny zpusob listovani collections
db.tabulka.insert({“name”:“tutorials point”}) … vlozi zaznam do collection movie
db.tabulka.count() … pocet radku
db.icorequests.find({“item.updated_iso”: “2018-03-13T15:54:44+0100”}, {href: 1, “item.updated_iso”: 1}) … filtr: jen zaznamy, kde je item.updated_iso rovno danemu retezci, uaze jen “href” zaznam a _id
db.icorequests.find({“item.created”: { $gt: 1512054095781 }}) … filtr za pouziti vetsi nez
db.COLLECTION_NAME.drop() … smaze collection
db.post.insert([ { title: 'MongoDB Overview', description: 'MongoDB is no sql database', by: 'tutorials point', url: 'http://www.tutorialspoint.com', tags: ['mongodb', 'database', 'NoSQL'], likes: 100 }, { title: 'NoSQL Database', description: “NoSQL database doesn't have tables”, by: 'tutorials point', url: 'http://www.tutorialspoint.com', tags: ['mongodb', 'database', 'NoSQL'], likes: 20, comments: [ { user:'user1', message: 'My first comment', dateCreated: new Date(2013,11,10,2,35), like: 0 } ] } ])
====Bezpecnost==== db.getUsers() … seznam uzivatelu
db.createUser({user: “reportsUser”, pwd: “abcdefgh”, roles: [ { role: “read”, db: “reporting” }, { role: “readWrite”, db: “accounts” ]}) … vytvori uzivatele
db.dropUser(“reportsUser”) … smaze uzivatele
====Import/Export==== mongoexport -d dbname -c colname | gzip > dump.txt.gz
zcat dump.txt.gz | mongoimport -d dbname -c colname
mongoimport -d db -c collection –jsonArray –file soubor.json
mongodump … export vsech databazi a tabulek
mongodump –archive=databaze.gz –gzip –db databaze … export jedne databaze
mongorestore … restore databaze z dumpu
mongorestore -d 0 ./0 –drop