query array, not includes

80 views
Skip to first unread message

marlor

unread,
Jan 19, 2011, 6:39:50 PM1/19/11
to Morphia
hi,

i have the following structure.

{"itemId" : "item111",
"lines" : [
{ "lineId" : "line111", "status" : { "statustype" : "AAA"} },
{ "lineId" : "line222", "status" : { "statustype" : "BBB"} }
]
}
{"itemId" : "item222",
"lines" : [
{ "lineId" : "line333", "status" : { "statustype" : "AAA"} },
{ "lineId" : "line444", "status" : { "statustype" : "AAA"} }
]
}
{"itemId" : "item333",
"lines" : [
{ "lineId" : "line555", "status" : { "statustype" : "CCC"} },
{ "lineId" : "line666", "status" : { "statustype" : "CCC"} }
]
}

How can I query all items which do not have all of its
lines.status.statustype AAA.
In case of statustype AAA, with the above sample, I want to retrieve
item with itemId item111 and item333. NOT item222 as both of it's
statustype is AAA.
Note: there can be more than two lines per item.

I tried the different query methods notEquals, hasNonOf ... but it
looks like they are not the implementation i am looking for as in this
case i am searching for fields within an array "lines".

any suggestions?

thank you,

marlor

Scott Hernandez

unread,
Jan 19, 2011, 6:57:45 PM1/19/11
to mor...@googlegroups.com
I think you want $not + $all; however I don't think we can express
that with the current fluent query system.

See if you can get what you want via the shell and I will see if that
can be represented with the current system, and if not we can add an
issue to support it.

Rick Chen

unread,
Sep 6, 2012, 6:55:29 PM9/6/12
to mor...@googlegroups.com
Hi Scott,

I need the $not + $all in this query:
{"myInts":{$not:{$all:[1,2]}}}

Here's the Java code:
List<Integer> ints = new ArrayList<Integer>();
ints.add(1);
ints.add(2);
Query q = createQuery().field("myInts").not.hasAll(ints);

This creates this instead:
{"myInts":{"$all":{"$not":{"$not":[1,2]}}}}

How do I create the original query above through Morphia?

Thanks,
Rick

Jeremy Johnson

unread,
Sep 14, 2012, 3:43:51 PM9/14/12
to mor...@googlegroups.com

Just to better my understanding of Morphia, if a query such as this isn't supported by Morphia we still have the option of using the Java driver for the query and then using Morphia for the DBObject -> POJO mapping, right?

Thanks.

Russell Bateman

unread,
Sep 14, 2012, 3:47:55 PM9/14/12
to mor...@googlegroups.com
In my DAO layer, I use both Morphia and, for stuff I haven't figured out how to do in Morphia, direct calls to the Java driver. The Mongo code in my project (switch EVERYTHING over from PostgreSQL) is now over 4 months old.
Reply all
Reply to author
Forward
0 new messages