I\'m trying to use rmongodb
to fetch information from a MongoDB database for further processing in R. However, I have some difficulties to really get started. This
Now, what if I want to find people whose first name is either "John" or "Bob" or "Catherine"?
You can use the $in operator for this:
cursor <- mongo.find(mongo, "test.people",
list(last.name="Smith",
first.name=list('$in'=c('John','Bob','Catherine'))
)
)
It would be worth having a read of the MongoDB Advanced Queries page as well as Dot Notation (Reaching Into Objects).
Another issue is that the database content is nested, which means I have subtrees, subsubtrees etc.
The data structure sounds potentially challenging to manipulate; would need a practical example of a document to try to illustrate the query.
So what if I want to find all people with first name "John" who are 40 years old and were unemployed in 2010? What would the query look like?
Making some assumptions on the data structure, here is an example of a simple "and" query:
cursor <- mongo.find(mongo, "test.people",
list(
first.name='John',
fy2012.job='unemployed',
age = 40
)
)
It's not really an answer as I'm still struggling with some aspects myself, but this might help to get you started: Running advanced MongoDB queries in R with rmongodb
Also, check the example application that ships with the rmongodb page. That is, which is accessible at the github package: https://github.com/gerald-lindsly/rmongodb/blob/master/rmongodb/demo/teachers_aid.R