MongoDb-命令删除需要身份验证

时间:2020-07-15 14:59:56

标签: mongodb

我有以下命令

mongo clean_collection.js --host localhost --username root --password example

Clean_collection.js文件包含:

conn = new Mongo();
db = conn.getDB("MyDb");
var myColl = db.getCollection('MyCollection');
myColl.drop();

但是MongoDb返回:

MongoDB shell version v4.2.8
connecting to: mongodb://localhost:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("22d094e1-fb65-46c8-a9e6-386c1678c680") }
MongoDB server version: 4.2.8
2020-07-15T10:33:00.787-0400 E  QUERY    [js] uncaught exception: Error: drop failed: {
"ok" : 0,
"errmsg" : "command drop requires authentication",
"code" : 13,
"codeName" : "Unauthorized"
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DBCollection.prototype.drop@src/mongo/shell/collection.js:696:15

我也在使用MongoDb .NET驱动程序,我可以删除集合,而不会遇到使用.NET驱动程序的任何问题。

0 个答案:

没有答案