I have a mongodb
database and I calculated prediction using my mongo documents in R, for this I used the R rmongodb
library. I can read documents which have a simple key value. However, I don't know how to read nested mongo data in R. Does any one know how to access nested documents in R?
Asked
Active
Viewed 539 times
0
-
Can we see structure (`str()`) of your object? – Roman Luštrik May 08 '14 at 07:35
-
Did you see [this question & answer](http://stackoverflow.com/questions/12003402/queries-in-mongodb/12074341#12074341)? – Jaap May 08 '14 at 07:51
1 Answers
0
It really depends on what you wanna read from the BSON structure.
For maps like this {'mapping': {'a':123, 'b':456}}, it's as easy as
mongo.bson.value(cval,"mapping.a")
or
mongo.bson.value(cval,"mapping.b")
However, for list structure like this {'list':[1,2,3,4,5]}, you need to use a loops to read them out:
for (item in mongo.bson.value(cval,"list")) {
print(item)
}
You can find the whole example in this tutorial: http://winston.attlin.com/2014/01/building-up-easy-data-analysis-platform.html

Winston Chen
- 6,799
- 12
- 52
- 81