Unable to see collections in mongo DB when connected through R

此生再无相见时 提交于 2020-01-22 00:40:28

问题


I used "rmongodb" package to connect to mongo DB through R. The connection is successful.

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

If I check at the host where mongoDB is running.

> use reporting
switched to db reporting

> show collections
MongoIndexing
details
test
>

But from R

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

回答1:


The below code will return an array of collection names iff the provided database has collections in it. Otherwise, it will return character(0)

try this:

mongo <- mongo.create(host="127.0.0.1:27017" , db="sample")
mongo.get.database.collections(mongo , "sample")

Output: two collections named roles and categories

"sample.roles"          
"sample.categories" 

To get all databases:

mongo <- mongo.create(host="127.0.0.1:27017")
mongo.get.databases(mongo)

To get all collections in a specific database say sample:

mongo.get.database.collections(mongo, "sample")

You can check rmongod link for more info.



来源:https://stackoverflow.com/questions/32582323/unable-to-see-collections-in-mongo-db-when-connected-through-r

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