简体   繁体   English

MongoDB - 使用 mongoimport 导入 JSON 数据失败

[英]MongoDB - Failed to import JSON data using mongoimport

Hello guys I'm trying to import JSON file to my collection in mongodb database but keeps give me an error.大家好,我正在尝试将 JSON 文件导入到我在 mongodb 数据库中的集合中,但一直给我一个错误。 how to import this json file?如何导入这个 json 文件? I tried using mongodb compass and mongoshell give me this error我尝试使用 mongodb 指南针和 mongoshell 给我这个错误

E  QUERY    [js] uncaught exception: SyntaxError: unexpected token: identifier :      
@(shell):1:14

This is the file: https://github.com/pedox/indonesia-mongo/blob/master/indonesia.json这是文件: https://github.com/pedox/indonesia-mongo/blob/master/indonesia.json

My mongoimport command:我的 mongoimport 命令:

mongoimport --jsonArray --db DB_Pro --collection indonesia --file:C:\Users\sekti\Downloads\db indonesia\Indonesia-mongo\indonesia.json

Just open the terminal in the folder your .json file is located in. Here is one I do to import the data in Ubuntu .只需在.json文件所在的文件夹中打开终端。这是我在Ubuntu中导入数据的方法。

  1. Open a folder and Open in terminal打开一个文件夹并Open in terminal

  2. Download the file:下载文件:

     curl -o data.json https://raw.githubusercontent.com/pedox/indonesia-mongo/master/indonesia.json
  3. Import the file:导入文件:

     mongoimport --host=localhost --port=27017 --username=gotqn --collection=trades --db=github --file=data.json --authenticationDatabase admin

So, I need to specify the host and the port .所以,我需要指定hostport Also, because I am using a password to authenticated I need to specify the username and the authenticationDatabase and then enter the password when asked.另外,因为我使用密码进行身份验证,我需要指定usernameauthenticationDatabase ,然后在询问时输入密码。

Also, as there are various options - check the official docs .此外,由于有多种选择 - 请查看 官方文档

Try using Studio3t.尝试使用 Studio3t。 it is very user friendly to use MongoDB and provides many functionalities to operate on db and collections使用 MongoDB 非常用户友好,并提供许多功能来操作 db 和 collections

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

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