jeroen / mongolite

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

finding nested fields #157

Closed ericpgreen closed 5 years ago

ericpgreen commented 5 years ago

Let's say I have a collection called myCollection that looks like this:

_id: "something"
fieldA: 0
object1: Object
     nestedObject1: Object
          fieldB: 0
          fieldC: 1
fieldD: 1
object2: Object
     nestedObject2: Object
          fieldE: 0
          fieldF: 1

How can I use find() to get a dataframe of fieldA, fieldB, and fieldC? I'm very new to Mongo, and I'm not quite sure how to make a reproducible example. Sorry!

ericpgreen commented 5 years ago

My approach so far has been:

df <- myCollection$find(fields = '{"fieldA": true, "object1.nestedObject1": true}')

But it gives a dataframe of 3 variables:

ericpgreen commented 5 years ago

I believe the issue was a bit localized. My real field is named something like object1.nestedObject1:something, so I was wrapping the nested name in backticks.

object1.`nestedObject1:something`

Removing the backticks worked, so there is no issue.

sarahollis commented 4 years ago

Hi Eric, I am having the same issue , I was wondering if you could post an example of your solution here?

ericpgreen commented 4 years ago

For me just removing the backticks did the trick:

object1.nestedObject1:something

sarahollis commented 4 years ago

I am able to extract the field properly for a nested field just on the second level (as your example above) but not for further nested fields i.e. object1.nestedObject1.nestednestedObject1:something, For those fields (nestednestedObject1), I get just the second level that is brought back (object1.nestedObject1), with list() as the response that appears. Any ideas? --------------------------------------------------- Sara Hollis, MSc Emergency, Trauma and Acute Care Programme World Health Organization Geneva, Switzerland

Whatsapp +1 281 300 7209 Mobile +41 78 247 4807

On Thu, Nov 21, 2019 at 6:45 PM Eric Green notifications@github.com wrote:

For me just removing the backticks did the trick:

object1.nestedObject1:something

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jeroen/mongolite/issues/157?email_source=notifications&email_token=ANT3LKLJWP6F7GSSK3U3UD3QU23J7A5CNFSM4F56IUU2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEE24E5Y#issuecomment-557171319, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANT3LKJS3O7JUVWIKZ54XTTQU23J7ANCNFSM4F56IUUQ .

ericpgreen commented 4 years ago

Hopefully someone else can weigh in. I have a pretty loose grasp of json.

On Fri, Nov 22, 2019 at 4:57 AM sarahollis123 notifications@github.com wrote:

I am able to extract the field properly for a nested field just on the second level (as your example above) but not for further nested fields i.e. object1.nestedObject1.nestednestedObject1:something, For those fields (nestednestedObject1), I get just the second level that is brought back (object1.nestedObject1), with list() as the response that appears. Any ideas? --------------------------------------------------- Sara Hollis, MSc Emergency, Trauma and Acute Care Programme World Health Organization Geneva, Switzerland

Whatsapp +1 281 300 7209 Mobile +41 78 247 4807

On Thu, Nov 21, 2019 at 6:45 PM Eric Green notifications@github.com wrote:

For me just removing the backticks did the trick:

object1.nestedObject1:something

— You are receiving this because you commented. Reply to this email directly, view it on GitHub < https://github.com/jeroen/mongolite/issues/157?email_source=notifications&email_token=ANT3LKLJWP6F7GSSK3U3UD3QU23J7A5CNFSM4F56IUU2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEE24E5Y#issuecomment-557171319 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/ANT3LKJS3O7JUVWIKZ54XTTQU23J7ANCNFSM4F56IUUQ

.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/jeroen/mongolite/issues/157?email_source=notifications&email_token=AAEFNAO6X6C336EUMV7ZRPLQU6UJJA5CNFSM4F56IUU2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEE5EZJY#issuecomment-557468839, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEFNAMPGLI3LPENSCVV4OTQU6UJJANCNFSM4F56IUUQ .