如何使用scala reactivemongo播放确保成功进行身份验证

时间:2015-12-29 00:38:40

标签: mongodb scala authentication reactivemongo

我正在使用reactivemongo连接到MongoDB。

val connection: MongoConnection = driver.connection(hosts, options = conOpts, authentications = List(credentials))
val db = connection(database)
val collection = db(collection)
val resultData = collection.find(query, filter)

第一次尝试查询数据库时,我得到了一个:

Error executing MongoDB Query reactivemongo.core.errors.DetailedDatabaseException: DatabaseException['not authorized for query on test.test' (code = 13)]

如果我再试一次,查询通常会成功。我认为这是因为第一次调用find方法时,身份验证没有时间成功完成。

所以我想知道是否有办法检查身份验证的状态,以便在查询数据库之前等待它完成?

1 个答案:

答案 0 :(得分:0)

Reactivemongo> 0.11.x应该支持SHA1授权,但不是默认值,要启用它,只需在mongodb.uri的末尾添加“?authMode = scram-sha1”

uri = "mongodb://userName:password@localhost/databaseName?authMode=scram-sha1"