When using rmongodb, unable to see collections in mongoDB

情到浓时终转凉″ 提交于 2019-11-27 07:33:38

问题


I am having the same issue as in this thread:Unable to see collections in mongo DB when connected through R

I am successfully connected to mongoDB.

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

If I run the following code, I see the correct db.

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

But, when I try to view the collections, it returns character(0)

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

If I connect from the shell I can see all the collections, so I know they exist.

> use FF
switched to db FF

> show collections
kelp_classifications
kelp_groups
kelp_subjects
kelp_users

回答1:


Update 2017-09-25

rmongodb is no longer supported and removed from CRAN

Reference: https://github.com/dselivanov/rmongodb


This function is working correctly for me in 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:


The following code seems to work in situations where mongo.get.database.collections(mongo, db = db) results in 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)


来源:https://stackoverflow.com/questions/34752065/when-using-rmongodb-unable-to-see-collections-in-mongodb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!