2015-04-19 143 views
2

我使用R并尝试使用最近的“Mongolite”。但是我无法连接到MongoDB服务器。 手册明确规定以下内容:使用Mongolite R验证凭证失败

mongo(collection = "test", db = "test", url = "mongodb://localhost") 

这是我没有成功尝试,在那里我有一个日志令牌和课程的端口。

mongodb://heroku:[email protected]:PORT 

,并不断收到以下错误:

Error in mongo_collection_new(url, db, collection) : 
    Failed to authenticate credentials. 
+0

什么版本的MongoDB您使用的是? – Stennie

+0

mongoDB ver。 2.4.8 –

回答

1

如果你看看jeroenooms的源代码/ mongolite你可以看到,它不支持认证尚未:

https://github.com/jeroenooms/mongolite/blob/master/R/mongo.R

mongo_collection_new <- function(uri = "mongodb://localhost", db = "test", collection = "test"){ 
stopifnot(is.character(uri)) 
stopifnot(is.character(db)) 
stopifnot(is.character(collection)) 
.Call(R_mongo_collection_new, uri, db, collection) 
} 
3

这是尝试和真实蒙戈(今天v0.7)支持认证连接到一个远程 3.2.x MongoDB(而不是本地主机)。

下面jeroenooms的例子提供自己的工作:

library(mongolite) 
mongo(collection = "mtcars", url = "mongodb://readwrite:[email protected]:43942/jeroen_test") 

为了解释:

  • mtcars是MongoDB的 “收藏” 的名称(或 “表”,如果你坚持)。这可能是一个尚不存在的名字。
  • readwrite是你的MongoDB的用户名
  • test为用户“读写”
  • ds043942.mongolab.com是远程主机,它可以通过IP地址来代替,即23.20.234.21
  • 43942是的密码端口号。默认情况下在MongoDB中,它是27017
  • jeroen_test是已经存在

运行上面的命令在R将打印使用,这对数据库实例的名称:

Mongo Message: SCRAM: authenticating "readwrite" (step 1)

Mongo Message: SCRAM: authenticating "readwrite" (step 2)

Mongo Message: SCRAM: authenticating "readwrite" (step 3)

Mongo Message: SCRAM: "readwrite" authenticated

...


我试图用我自己的远程主机信息替换它。它在一开始并没有工作,这转而成为用户角色问题,而不是mongolite问题。确保用户具有正确的readWrite角色后,我通过mongolite包连接到我的远程3.2.x MongoDB。

以下2个来源是有很大的帮助我在MongoDB中设置用户: