【问题标题】:When using rmongodb, unable to see collections in mongoDB使用 rmongodb 时,在 mongoDB 中看不到集合
【发布时间】:2016-01-12 19:20:39
【问题描述】:

我在这个帖子中遇到了同样的问题: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

【问题讨论】:

  • 我刚刚通过恢复到 mongoDB 版本解决了这个问题。 3.0.8.

标签: r mongodb rmongodb


【解决方案1】:

2017 年 9 月 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"

【讨论】:

    【解决方案2】:

    以下代码似乎适用于 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-13
      相关资源
      最近更新 更多