1

我在这个线程中遇到了同样的问题:Unable to see collections in mongo DB when connected through R

我已成功连接到 mongoDB。

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

如果我运行以下代码,我会看到正确的 db.

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

但是,当我尝试查看集合时,它返回 character(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
4

2 回答 2

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"
于 2016-03-14T09:01:25.247 回答
0

以下代码似乎适用于 mongo.get.database.collections(mongo, db = db) 导致 character(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)
于 2018-04-28T11:42:49.417 回答