Recent Changes - Search:

Oktatás

* Programozás 2
  + feladatsor
  + C feladatsor
  + Python feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

* levelezősök
  + Adator. prog.
  + feladatsor
  + quick link

teaching assets


Félévek

* 2024/25/1
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Scala


[ edit | logout ]
[ sandbox | passwd ]

Commands

MongoDB Commands

Dump a database:

mongodump -d <db_name>

Where <db_name> is the name of the database you want to dump.


Restore a database:

mongorestore [--drop]

Supposing you are in the directory where the folder dump/ is located.

If you specify --drop, then collections before restoration will be deleted in the database (and they'll be re-created from scratch during the restoration process).


Restore a specific collection:

mongorestore [--drop] -d <db_name> -c <coll_name> dump/file.bson

# concrete example:
# mongorestore --drop -d movies -c movieDetails dump/movieDetails.bson

If you specify --drop, then the collection will be deleted before restoring it. Meaning of the example above: "take the content of dump/movieDetails.bson, and restore it in the database movies, in the collection movieDetails".


Import from a JSON file #1:

Suppose you have a JSON file, where each line contains a document:

{ name: "Widget 1", desc: "This is Widget 1" }
{ name: "Widget 2", desc: "This is Widget 2" }

You can import it the following way:

mongoimport [--drop] -d <db-name> -c <coll-name> --type json location/of/input.json

Import from a JSON file #2:

Suppose you have a JSON file, where you have an array of documents:

[
    {
        "color": "red",
        "value": "#f00"
    },
    {
        "color": "green",
        "value": "#0f0"
    }
]

You can import it the following way:

mongoimport [--drop] -d <db-name> -c <coll-name> --type json --jsonArray location/of/input.json

Make sure you are using the --jsonArray flag!

Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2023 November 22, 15:48