jeroen / mongolite

Fast and Simple MongoDB Client for R
https://jeroen.github.io/mongolite/
286 stars 65 forks source link

Equivalent to Select * for a nested document #156

Closed Btibert3 closed 5 years ago

Btibert3 commented 5 years ago

Right now, my collection has 1 document:

> m$count()
[1] 1

And to pull the entire document, and get the nested data that I am looking for, is possible with an empty find.

pbp_tmp = m$find('{}')
pbp_plays = pbp_tmp$liveData$plays$allPlays
plays = pbp_plays[[1]]

This matches my expectations:

> class(plays)
[1] "data.frame"
> nrow(plays)
[1] 364

But what I was hoping to do was something like below:

allplays = m$find('{"liveData.plays.allPlays":{}}')

but this returns:

> class(allplays)
[1] "data.frame"
> nrow(allplays)
[1] 0

Finally, my question. How can we return all of the contents for a nested document. If the query above should have done it, the one that returns 0 rows, what could I possibly be doing wrong?

However, because I am very novice when it comes to mongodb, I suspect that I am missing something very obvious here.

jeroen commented 5 years ago

Maybe try setting the fields parameter (instead of query) like this:

allplays = m$find(fields = '{"liveData.plays.allPlays":1}')
Btibert3 commented 5 years ago

Thanks!