0

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?

Jaap
  • 81,064
  • 34
  • 182
  • 193
Neo-coder
  • 7,715
  • 4
  • 33
  • 52

1 Answers1

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