Рубрики
Uncategorized

Экспорт и импорт базы данных mongodb

Автор оригинала: David Wong.

Экспорт базы данных

Export type is json, database: mapdb, set: bike field: bikeId, lat, lng, current_time, source, if the source field is the first data of ofo
mongoexport --port 27017 -u sangfor_edr -p Sangforedr! -d sangfor_edr -c agent_info --type=json -o agent_info.json

Импорт базы данных

mongoimport --port 27017 -u sangfor_edr -p Sangforedr! -d sangfor_edr -c anti_bfa_log  --type=json --file anti_bfa_log.json

Ps: Для выполнения в каталоге установки mongodb

Параметрическое Значение

  • экспорт
- h, - - host: Represents the remote connection database address, default connection to the local Mongo database;
Port: Represents the port of the database connected remotely, with the default remote port 27017;
- U -- username: Represents the account connected to the remote database. If the authentication of the database is set, the user account needs to be specified.
- P -- password: The password corresponding to the account connecting to the database;
- D -- db: Represents the connected database;
- C -- collection: Represents the collection in the connected database;
- F -- fields: Represents the fields in the collection, and you can select the exported fields according to the settings.
- type: The file type representing the export output, including CSV and JSON files;
- O -- out: Represents the name of the exported file;
- Q -- query: Represents the query condition;
Skp: skip a specified number of data;
- limit: read a specified number of data records;
Sort: Data can be sorted by specifying the field of sorting by parameters, and by using 1 and - 1 to specify the way of sorting, where 1 is in ascending order and - 1 is in descending order, such as sort ({KEY:1}).
 When querying, sort, skip, limit are used at the same time, regardless of location, sort first, skip then limit.
  • Импорт
H,--host: Represents the remote connection database address, default connection to the local Mongo database;
Port: Represents the port of the database connected remotely, with the default remote port 27017;
- u, - username: Represents the account connecting to the remote database. If the authentication of the database is set, the user account needs to be specified.
- p,--password: the password corresponding to the account connecting to the database;
- d,--db: Represents the connected database;
- c,--collection: Represents the collection in the connected database;
- f, - - fields: Represents the fields in the imported collection;
Type: Represents the file type imported, including CSV and json, TSV files, default JSON format;
--file: The name of the imported file
Headerline: When importing a CSV file, specify that the first row is the column name and does not need to be imported.