简体   繁体   English

在 MongoDB 中导入 JSON 或 CSV 文件

[英]Importing JSON or CSV file in MongoDB

I'm new to MongoDB in Windows 7 and I tried to import JSON and CSV file into MongoDB.我是 Windows 7 中的 MongoDB 新手,我尝试将 JSON 和 CSV 文件导入 MongoDB。

1.First i tried importing JSON file using the command 1.首先我尝试使用命令导入 JSON 文件

"C:\>mongodb\bin\mongoimport –host localhost:27017 –db mydb –collection docs"

and it showed this error它显示了这个错误

"exception:BSON representation of supplied JSON is too large: code FailedToParse: FailedToParse: Expecting '{': offset:0" 

2.When i import CSV file i used the command 2.当我导入CSV文件时,我使用了命令

"C:\mongodb\bin>mongoimport --db mynewdb --collection message --type csv --fields
form,Iname,fistname,lastname --file d:\new folder\csv1.csv" 

and i get the error message as我收到错误消息

"ERROR: multiple occurrences
Import CSV, TSV or JSON data into MongoDB.
When importing JSON documents, each document must be a separate line of the input file"

I downloaded JSON and CSV bulk file randomly by browsing.我通过浏览随机下载了 JSON 和 CSV 批量文件。 I want to know whether it will get imported when data's are non-organized or should the data be organized?我想知道当数据是非组织的还是应该组织数据时它是否会被导入? If so where can get a complete bulk JSON and CSV file which is ready to import.如果是这样,哪里可以获得准备导入的完整批量 JSON 和 CSV 文件。

尝试在查询结束时使用 --jsonArray 标志,这样它看起来像

C:\>mongodb\bin\mongoimport –host localhost:27017 –db mydb –collection docs --jsonArray

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM