When i deploy my cms it is unable to perform a particular query on the underlying mongo-db. I keep getting the following error:
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)
The mongodb user has "readWrite" permissions on the said "cms-db".
show users
{
"_id" : "cms-db.cmsuser",
"user" : "cmsuser",
"db" : "cms-db",
"roles" : [
{
"role" : "readWrite",
"db" : "cms-db"
}
]
}
All the necessary collections are created during boot-up. Because of this authorization issue, the server is not able to start and the app crashes.
use cms-db
switched to db cms-db
show collections
aposAttachments
aposCache
aposDocVersions
aposDocs
aposLocks
aposUsersSafe
sessions
Can somebody tell me if I am doing something wrong in terms of the permissions or anything else?
Thanks.
I was able to reproduce this with Atlas. You are attempting to use a mongodb+srv URL, which is what Atlas recommends when using the MongoDB driver 3.6 or better. Apostrophe 2.x is currently on the MongoDB 2.x driver, so that doesn't work.
You need to use the older style of URL which you can see on Atlas if you click the "I am using driver 3.4 or earlier" tab instead:
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
When I do it this way I have no trouble connecting.
If you are eager to use a newer version of the MongoDB driver, and the new style of URI, you can use the apostrophe-db-mongo-3-driver module. But, this isn't currently mandatory to be successful with Atlas.
In Apostrophe 3.x we will of course use the newer generation of driver out of the box.
(One last FYI - MongoDB driver versions and MongoDB server versions are not the same thing. You don't need the 3.6 driver to connect to 3.6, for instance.)