我尝试将JSON文件导入MongoDB,但收到以下错误
VK360@VK360:~$ mongoimport --db cstore --collection stores --drop --file /home/kuliza360/Desktop/Office/Cstoredemo/my_data.json
2018-04-04T10:37:41.545+0530 connected to: localhost
2018-04-04T10:37:41.545+0530 dropping: cstore.stores
2018-04-04T10:37:41.545+0530 Failed: not authorized on cstore to execute command { drop: "stores" }
2018-04-04T10:37:41.545+0530 imported 0 documents
我跟随Link并在mongo shell中执行了下面提到的步骤,但仍然有相同的错误。
use admin
db.createUser(
{
user: "admin",
pwd: "password",
roles: [ { role: "root", db: "admin" } ]
}
);
exit;
执行后执行错误
2018-04-04T10:33:58.124+0530 E QUERY [thread1] Error: couldn't add user: not authorized on admin to execute command { createUser: "admin", pwd: "xxx", roles: [ { role: "root", db: "admin" } ], digestPassword: false, writeConcern: { w: "majority", wtimeout: 60000.0 } } :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1267:15
@(shell):1:1
答案 0 :(得分:0)
使用查询
mongoimport --db cstore --collection stores --drop --file /home/kuliza360/Desktop/Office/Cstoredemo/my_data.json --username admin --password password
而不是
mongoimport --db cstore --collection stores --drop --file /home/kuliza360/Desktop/Office/Cstoredemo/my_data.json
答案 1 :(得分:0)
在--file之前添加--jsonArray
mongoimport --db cstore --collection存储--drop --jsonArray --file /home/kuliza360/Desktop/Office/Cstoredemo/my_data.json
希望这也可以帮助其他人!