使用rmongodb时,无法在mongoDB中看到集合

时间:2016-01-12 19:20:39

标签: r mongodb rmongodb

我遇到与此主题相同的问题:Unable to see collections in mongo DB when connected through R

我已成功连接到mongoDB。

> mongo.is.connected(mongo)
[1] TRUE

如果我运行以下代码,我会看到正确的数据库。

> mongo.get.databases(mongo)
[1] "FF"
> 

但是,当我尝试查看集合时,它返回字符(0)

> mongo.get.database.collections(mongo , db = "FF")
character(0)
>

如果我从shell连接,我可以看到所有的集合,所以我知道它们存在。

> use FF
switched to db FF

> show collections
kelp_classifications
kelp_groups
kelp_subjects
kelp_users

2 个答案:

答案 0 :(得分:1)

更新2017-09-25

rmongodb不再受支持并已从CRAN中删除

参考:https://github.com/dselivanov/rmongodb

此功能在v1.8.0

中正常运行
mongo <- mongo.create()
mongo.is.connected(mongo)
# [1] TRUE
db <- "test"
mongo.get.database.collections(mongo, db = db)
[1] "test.test"

答案 1 :(得分:0)

以下代码似乎适用于mongo.get.database.collections(mongo,db = db)导致字符(0)的情况

mongo = mongo.create(host = "127.0.0.1:9997", db = "restaurant")

# Create a mongo.bson object with header as "listCollections", which is 
# a mongo DB command
command = list(listCollections = "") 
command = mongo.bson.from.list(command)
command
>listCollections : 2     

# calling mongo DB server to return collections as mongo.bson object
collections = mongo.command(mongo, "restaurant", command)

# convert mongo.bson object to a list 
collections = mongo.bson.to.list(collections)