0

I have the following DB structure:

{  id : "1233454",
   name : "abc",
   elements : [ 
        { "1" : { id : "123", referenceId : "567" } },
        { "2" : { id : "345" } },
   ],
},
{  id : "56789",
   name : "def",
   elements : [ 
        { "3" : { id : "123", referenceId : "789" } },
        { "4" : { id : "345" } },
   ],
},
{  id : "98765",
   name : "def",
   elements : [ 
        { "3" : { id : "123", referenceId : "789" } },
        { "4" : { id : "345" } },
   ],
}

and I need to retrieve document id where referenceId is equals to the parameter passed to the method. For example: If method receives "789" it should return "56789" and "98765".

Thanks in advance.

3
  • is there any particular rule/schema for the keys in your elements array elements? Can it be any string? Commented Dec 13, 2013 at 12:17
  • id field is the key of the document. "1233454", "56789" and "98765" are document keys. Commented Dec 13, 2013 at 12:27
  • you seem to get my question wrong, see my answer below... Commented Dec 13, 2013 at 12:32

1 Answer 1

1

It is not recommended to have unknown keys if you want to query efficiently, see for example this discussion. If your keys in the elements (e.g. "1") follow a certain structure or are limited, you could use a simple $or in the query to check all options such as "elements.1.referenceId" - see here how to do this.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.