I think you're looking for $elemMatch:
http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-ConditionalOperator%3A%24elemMatch
On Wed, May 19, 2010 at 2:39 PM, matt <
mathia...@gmail.com> wrote:
> hi guys,
> I have the json documents that follow this example:
>
> "container" : {
> "attributes" : {
> "attribute" : [
> { "def" : { "elements" : {
> "element" : [ { "value" : "a"} , { "value" : "b"} , { "value" :
> "c"} , { "value" : "d"}]} ,
> "defaultValue" : { "value" : "a"}} ,
> "name" : "att1"
> } ,
> { "def" : {
> "upperBound" : {"value" : "10"} ,
> "lowerBound" : {"value" : "5"} ,
> "initValue" : {"value" : "5"}} ,
> "name" : "att2"
> } ,
> { "def" : {
> "upperBound" : {"value" : "20"} ,
> "lowerBound" : {"value" : "15"} ,
> "initValue" : {"value" : "15"}} ,
> "name" : "att3"
> }
> ]
> }
> }
> my objective is to do a query to retrieve a "container" by querying
> its attributes based on an attribute name and whether or not it
> matches a particular value.
> if I use this query:
>
> BasicDBObject query = new BasicDBObject();
> query.put("
container.attributes.attribute.def.name","att3");
> query.put("container.attributes.attribute.def.elements.element.value","a");
>
> to retrieve a container that has an attribute named att3 and that has
> a value of "a"
>
> I understand the query is incorrect because the first part of the
> query is not linked to the second part of the query. here name=att3
> matches but att3 doesn't have elements.element.value"="a", this gets
> matched with att1.
>
> in an xpath query I would write something like this; container/
> attributes/attribute/def[name="att3" and elements/element/value =
> "a"]. How can I do this with Mongo DB?
>
> thanks,
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to
mongod...@googlegroups.com.
> To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/mongodb-user?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to
mongod...@googlegroups.com.
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/mongodb-user?hl=en.