Import and export MongoDB collections
Quick links
| Ubuntu 22.04 | Mongo import | Mongo export
Prepare a mongo server instance:
|
|
We are in the container, so all command will run from root!
Import
MongoDB is one of the most popular NoSQL database engines. For our test we can take the most popularsample MongoDB database about restaurants:
|
|
Let’s import it into database mydb
and collection restaurants
using mongoimport
. Mongo will create :
|
|
Connect to out mydb
:
|
|
Count the documents in collection restaurants
and check a document in restaurants
:
|
|
Export
We should use mongoexport
to export the restaurants
collection from the mydb
database which we have previously imported
|
|
If you need to get a part of our collection. For example, let’s find all the restaurants which satisfy the criteria to be situated in the Bronx borough and to have Italian cuisine:
|
|
Usefull link here