撇号 mongo db 用户无权执行命令

Apostrophe mongo db user not authorized to execute command

当我部署我的 cms 时,它无法对基础 mongo-db 执行特定查询。我不断收到以下错误:

MongoError: not authorized on cms-db to execute command { find: "aposDocs", filter: { $and: [ { $and: [ { $and: [ { title: "guest" }, {} ] }, { $or: [ { trash: { $exists: 0 } }, { trash: false } ] } ] }, { type: "apostrophe-group" } ] }, sort: { updatedAt: -1 }, projection: {}, limit: 1 }
at Function.MongoError.create (/var/app/current/node_modules/mongodb-core/lib/error.js:31:11)
at queryCallback (/var/app/current/node_modules/mongodb-core/lib/cursor.js:212:36)
at /var/app/current/node_modules/mongodb-core/lib/connection/pool.js:469:18
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)

mongodb 用户对上述 "cms-db" 具有 "readWrite" 权限。

    show users
    {
        "_id" : "cms-db.cmsuser",
        "user" : "cmsuser",
        "db" : "cms-db",
        "roles" : [
            {
                "role" : "readWrite",
                "db" : "cms-db"
            }
        ]
    }

所有必要的集合都是在启动期间创建的。由于此授权问题,服务器无法启动且应用程序崩溃。

    use cms-db
    switched to db cms-db
    show collections
    aposAttachments
    aposCache
    aposDocVersions
    aposDocs
    aposLocks
    aposUsersSafe
    sessions

有人可以告诉我我是否在权限或其他方面做错了什么吗?

谢谢。

我能够用 Atlas 重现这个。您正在尝试使用 mongodb+srv URL,这是 Atlas 在使用 MongoDB 驱动程序 3.6 或更高版本时推荐的。撇号 2.x 当前在 MongoDB 2.x 驱动程序上,因此它不起作用。

您需要使用 URL 的旧样式,如果您改为单击 "I am using driver 3.4 or earlier" 选项卡,您可以在 Atlas 上看到它:

mongodb://user:password@test-shard-00-00-some-address.mongodb.net:27017,test-shard-00-01-some-address.mongodb.net:27017/test?ssl=true&replicaSet=your-replica-set-name&authSource=admin&retryWrites=true

当我这样做时,连接没有问题。

如果你渴望使用更新版本的MongoDB驱动程序,以及新样式的URI,你可以使用apostrophe-db-mongo-3-driver模块。但是,目前这并不是使用 Atlas 取得成功所必需的。

在 Apostrophe 3.x 中,我们当然会使用开箱即用的新一代驱动程序。

(仅供参考 - MongoDB 驱动程序版本和 MongoDB 服务器版本不是一回事。例如,您不需要 3.6 驱动程序连接到 3.6。)