Apostrophe Mongo数据库用户无权执行命令

时间:2018-08-10 16:47:07

标签: apostrophe-cms

当我部署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

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

谢谢。

1 个答案:

答案 0 :(得分:1)

我能够用Atlas来重现此内容。您正在尝试使用mongodb + srv URL,这是Atlas在使用MongoDB驱动程序3.6或更高版本时建议的URL。 Apostrophe 2.x当前位于MongoDB 2.x驱动程序上,因此不起作用。

如果您单击“我正在使用驱动程序3.4或更早版本”选项卡,则需要使用在Atlas上可以看到的URL的较旧样式:

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中,我们当然会使用现成的新一代驱动程序。

(最后一个FYI-MongoDB驱动程序版本和MongoDB服务器版本不是同一回事。例如,不需要3.6驱动程序即可连接到3.6。)