如何将数据导入mongoDB [英] How to import data into mongoDB

查看:166
本文介绍了如何将数据导入mongoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试导入JSON格式的大数据文件.我正在使用

I'm trying to import a large data file in JSON format . I'm using

mongoimport --db verbs --collection de --file "/Users/marcelbraasch/Downloads/de.json"

导入数据.这正在经历,但是,我遇到了以下异常:

to import the data. This is going through, however, I'm getting the following exception:

失败:(未经授权)未经动词授权执行命令{插入:"de",命令:false,writeConcern:{w:多数"}},$ db:动词"}

Failed: (Unauthorized) not authorized on verbs to execute command { insert: "de", ordered: false, writeConcern: { w: "majority" }, $db: "verbs" }

我已经尝试过这样的组合

I already tried combinations like this

mongoimport -h localhost:27017 -u 'user' -p 'password' --db verbs --collection de --file "/Users/myname/Downloads/de.json"

但没有一个起作用.如果此信息很重要,我的mongo实例正在docker容器中运行.我需要做什么?

but none of it worked. My mongo instance is running in a docker container, if this information matters. What do I need to do?

推荐答案

此处找到答案.该缺少的关键字是authenticationDatabase.对我有用的命令是:

Found the answer here. This missing keyword was authenticationDatabase. The command that worked for me was:

mongoimport --db verbs --collection de --authenticationDatabase admin --username user --password password --drop --file /Users/myname/Downloads/de.json.

这篇关于如何将数据导入mongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆