← 返回命令列表

Linux command

mongoimport 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Import JSON file

mongoimport --db [dbname] --collection [coll] --file [data.json]

Import CSV file

mongoimport --db [dbname] --collection [coll] --type csv --headerline --file [data.csv]

Import with authentication

mongoimport -u [user] -p [pass] --db [dbname] --collection [coll] --file [data.json]

Import from URI

mongoimport --uri "[mongodb://host/db]" --collection [coll] --file [data.json]

Import with drop

mongoimport --db [dbname] --collection [coll] --drop --file [data.json]

Import JSON array

mongoimport --db [dbname] --collection [coll] --jsonArray --file [array.json]

说明

mongoimport imports data into MongoDB. It supports JSON, CSV, and TSV formats. The tool bulk loads documents. Useful for data migration and seeding databases.

参数

--db _NAME_
Database name.
--collection _NAME_
Collection name.
--file _FILE_
Input file path.
--type _TYPE_
File type (json, csv, tsv).
--headerline
Use first line as field names.
--drop
Drop collection before import.
--help
Display help information.

FAQ

What is the mongoimport command used for?

mongoimport imports data into MongoDB. It supports JSON, CSV, and TSV formats. The tool bulk loads documents. Useful for data migration and seeding databases.

How do I run a basic mongoimport example?

Run `mongoimport --db [dbname] --collection [coll] --file [data.json]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --db _NAME_ do in mongoimport?

Database name.