ricopan wrote:
> I have docs analogous to this:
>
> { 'values' : [2,3,4] }
>
> { 'values': [4] }
>
> { 'values' : [3,4,5,6,7,8,9,10,11] }
>
> I need a query that only returns the doc if ALL elements of the array
> match the desired criteria.
>
> Eg. something like (but not)
>
> { 'values' : { '$gt' : 1, '$lt': 5} })
You can only use the $all operator that requires a full list of needed
values - you can not use a range search here.
- -aj
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQGUBAEBAgAGBQJN0o2bAAoJEADcfz7u4AZjivELwMMX8FxeglwVf+T4NKXRC8kp
6H4yZzoX8GRhv54lra+QGIs0LvHyTGp7E1F4snDVHX08PRTo7yW34+z+ibSAhT/i
SHhjzIJh7R8mEiNwdH1a0uzAgRNQCqGWFuktWW8556vf6m5epsrKXKPquzq3vx22
0YjKQwDCq04qdRywq6xTAzHAzogobiX81kuxjP3cAHKmFfsfZ0OsDmI63wUDPzoP
CBcwbcgIrHeeURfg4lOlZTHn72t62EuokuHTsy632koDw/F2oVKRq+2QEBWZG8wn
zGAhRQ80OVBMDqONgxxGIfXUdS6fXb7xob+bLMhVz0VUK8rOTK7LYVRVVEgGX8sx
a2UjZfkkRzbanBlGT3VpcD9iivwyucVVCnjAaZ8JZD6TmwDfiq9YnS1AWmmIyPTR
ca0jnoSg6rneOd40MDw5QNsRbPJOxleD7sf94nvpPqq5TR2nih82wI40xol1ojt/
q8cmdRJqFzNjC9hnamlzYPKLZNNSYP0=
=pUQM
-----END PGP SIGNATURE-----
You have been asking about
"""
I need a query that only returns the doc if ALL elements of the array
match the desired criteria.
"""
and not about a negation....completely different topic.
- -aj
ricopan wrote:
> Yeah, the $all operator is clearly not what I need. I need to match
> all values in the doc array, not in the query.
>
> I suppose in the example I gave one might be able to write a query for
> the negation ($lt:1,$gt:5) and use $not, but I need a more general
> case where the negation is not known.
>
> On May 17, 9:00 am, Andreas Jung <li...@zopyx.com> wrote:
> ricopan wrote:
>>>> I have docs analogous to this:
>>>> { 'values' : [2,3,4] }
>>>> { 'values': [4] }
>>>> { 'values' : [3,4,5,6,7,8,9,10,11] }
>>>> I need a query that only returns the doc if ALL elements of the array
>>>> match the desired criteria.
>>>> Eg. something like (but not)
>>>> { 'values' : { '$gt' : 1, '$lt': 5} })
> You can only use the $all operator that requires a full list of needed
> values - you can not use a range search here.
>
> -aj
>>
lists.vcf
< 1KViewDownload
- --
ZOPYX Limited | zopyx group
Charlottenstr. 37/1 | The full-service network for Zope & Plone
D-72070 T�bingen | Produce & Publish
www.zopyx.com | www.produce-and-publish.com
- ------------------------------------------------------------------------
E-Publishing, Python, Zope & Plone development, Consulting
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQGUBAEBAgAGBQJN0pHWAAoJEADcfz7u4AZjUagLvi84CLbkjzq3IadlbccT88rN
4AtbJHkEGy3vdMijv4yaHmHvTg072WV1VsD0oE8xeHfJnPhSj7jxyGDmAKAMZZTi
xi+vxbleF3TxMybgJUFXeg4T6go7iSa8xg7v0wz4R+OLbd2nyMyiCsCOyNHYrpa0
ofuBr2TCrb+JfY3vKGmUF+warEs7XHbojCOwsVdQeLaW9D8TNOzq/pG+I63Eb+EP
mY/SAvL8WDQh+WarQQm/N5Lgh3p1m/HQ/VSsgwbiKnfLz3Spnfuch1ul+ZvZJHTK
5xKB4AOyGuA1r6LVzrzve0+o4YpevZqbxXk9ghVQMLEBtG7gimW7OgIwbtUGyHyG
aLwB4A7eMkzyg2CmSzOmSSj4Y7hR+hmre8/Qkc/nQVipFEs84lEJU+06khD7WCVr
eICe/nrytpOTdwHCyE85c0zDYCDHDwRK4DRVz2VRYQIqJ+vuEOilR4ZfHzy2zoz5
2IetLrH9M9CNrmlqYC0tv0JQ339Lwmc=
=+TxC
-----END PGP SIGNATURE-----
db.foo.find({"foo.shape": "square", "foo.color": "purple"})
It would be nice if they merged some of this array information into a single document. Took me hours to find it last night.
Hope this helps ;)
-aj
Thanks for testing that!
Unfortunately that was a bad example because it got us back to the
$all operator.
Ok, so my understanding is that the $all operator tests that all
elements in the Query array {$all:[red,blue,yellow]} are found in the
doc array; that is, the query array is a subset of the doc array. So
if I add another doc
docC = {'_id': 'baz', 'some_array':
['red','yellow','blue','purple']}
this will also be matched by your $all array, but is not what I want
because purple is not an element of red, yellow, or blue.
I guess another way to say this is that it appears that queries on doc
arrays implicitly are OR over all elements, where I need AND over all
elements.
On May 17, 1:10 pm, mcoolin <mcoo...@techie.com> wrote:
> I tried this with you sample data and it worked.
> db.rico.find({'some_array' : { $all: [ 'red', 'blue', 'yellow'] }})
--
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.
Scott Hernandez wrote:
>
>
> On Tue, May 17, 2011 at 3:34 PM, ricopan <lle...@gmail.com
> <mailto:lle...@gmail.com>> wrote:
>
> Thanks for testing that!
> Unfortunately that was a bad example because it got us back to the
> $all operator.
> Ok, so my understanding is that the $all operator tests that all
> elements in the Query array {$all:[red,blue,yellow]} are found in the
> doc array; that is, the query array is a subset of the doc array. So
>
>
> Yes, the query $all items must be a subset or exact match. Do you want
> an exact match only?
>
>
> if I add another doc
>
> docC = {'_id': 'baz', 'some_array':
> ['red','yellow','blue','purple']}
>
> this will also be matched by your $all array, but is not what I want
> because purple is not an element of red, yellow, or blue.
>
> I guess another way to say this is that it appears that queries on doc
> arrays implicitly are OR over all elements, where I need AND over all
> elements.
>
>
> $all is an AND, while $in is OR
That's what the names of the operators implictely imply and the
documentation and examples under
http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24all
are pretty clear...that's what I already explained in my first reply.
- -aj
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQGUBAEBAgAGBQJN00WMAAoJEADcfz7u4AZjka0Lvjf2lunn9p3BEjm3CNq+S+d5
RBodK/tSZc24XFTxAao2wMrP1CwySKrtiHezr2M104ZknZDTuexwDduHCUs+6Ocy
FbGTtWPAZsmLQITBuQZJm3jysL4YNJn01VN8/NGwAT7uZVTRL2DHHr6aMI1ikX6I
Z7Ax6qzWJ11H63LF7BHt3c/ik7LRpRkQWe++wAg+pyySogfpfTpZrISLsQvmVfjI
86HqpOVkhPUxuXfvP0s2a35ae+kcB9Ju7rpsKOSudR9CEYzwwGnNP4ejfY4rRo3y
sG6QN9JYH+4EjSga7t0bIghupCNwIP1M2RsM0iIjxOF2Od8OKw+XUNsCAvNlBjwH
9tTlIz+2+aAhsligZ4EIrnjQI4YDJEKs7NVHxjP0nuNFWFqgBMQ0D20OA79GjuV9
O2X004k2lJzM9mFNWRJROs4SmPF1x0I+AN4r2EsgGZ/r0WVctiuhz4CnYucPlGLE
UK09pk6MEctCzDxRirydleqeZEVxhxI=
=9KHk
-----END PGP SIGNATURE-----
mcoolin wrote:
> db.rico.find({some_array: {$size: 3}, 'some_array' : { $all: [ 'red',
> 'blue', 'yellow'] } })
> // would seen to be right but returns the wrong items - Is this a bug?
You can not specify the same key twice within a JS array. Once
definition will override the other one - basic JS know-how.
>
> // using a functuion
> f = function() {
> var rv = true,
> a = [ 'red', 'blue', 'yellow'],
> mc = 0, c, i;
> for(c=0; c<a.length ; c++){
> i=this.some_array.length;
> while (i--) {
> if (this.some_array[i] === a[c]) {
> mc++
> }
> }
> }
> print(mc)
> if(mc != this.some_array.length){
> rv=false;
> }
> return rv;
> };
> db.rico.find(f);
Server-side execution of code should be avoided since it will be much
slover - especially because indexes won't take into account. So this is
neither scalable nor advicable for large collections.
- -aj
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQGUBAEBAgAGBQJN098yAAoJEADcfz7u4AZjd7ULwMZgqEmGSV4e5qHDiL1tL3LW
p4FgfxoyAZFCPhzWYDBHDHbIboaqZVSxG174SRn24oC4pnX/eqfpQko6LV/CsFh7
cLebcu2jrAvwyAnnx6jdW4tXfvWKoZ6j7Jyy8TwYqLkDgjVWaiVT8IiwIK3koj76
hypbFzJFtQJajPgIL7QlMK/OWubGpfIwqSi6oonKX0CFTBCuhO+6Uvxkrr8v0Hle
i6eRgxkoKstHdl/QbSlqG6EIkPgRfABUl/nYatLzARmmMls7m/QeMa+2EhHyOfHD
djEAge+ArXYCG73A/nUjiL/T6lgF9oiBUf0Yq7dP7nezY4G+MfdCZTjcdwGWnO2G
DyiMP2CcUkvXdjEiwOR65NTMB5+BufRPvuxbdoKnCPvAM+UoJRuyVlQsHrR2a7tN
H1YRIoUURB9Wujewgw2ykVB/IPde9zlQS4xyAxXQ178nuIr8oKsXXzYZ/IW5nG/b
NxTRf+5VWo4GsVDP9nhc9pPwvDMf7N8=
=yR+u
-----END PGP SIGNATURE-----
I just give up.
- -aj
> --
> 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.
- --
ZOPYX Limited | zopyx group
Charlottenstr. 37/1 | The full-service network for Zope & Plone
D-72070 T�bingen | Produce & Publish
www.zopyx.com | www.produce-and-publish.com
- ------------------------------------------------------------------------
E-Publishing, Python, Zope & Plone development, Consulting
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQGUBAEBAgAGBQJN0+XRAAoJEADcfz7u4AZjkKgLvjTIvoTBscL7ZLdNHey3fNOT
pHzuBrrFs7ZEjVurSCAKU+PhR6vJpvZBDQ5a0jCtNvXOc227FsVqovKa8rIetnB+
Kzvv4vVkWzp8Ia02KzvS0Jw8gK8YKa+tXUq5qY4t2h2y3vYUF8NedGaD33369WLH
4NFVVjhTCRR0u3Qqtp8J2x9h/lNOhNv3qJUbeQofCGucIfdCI1M0Fu1JN4KhIueY
8vlJE1ZBn0oS/7Qr102pKr4kj2mac6TeRafahkWj7OArDnkIUlp5YcktlSC4U17T
xBNvnY42rIG8fghuA2rlaguI1z1Kfgn7+dvukKnXF5Qizs9PE29EeiwVdf+jgiX5
TP9mBwBqvjYTtjhAB9ck23Oadh85C6FKa5E5p9Vol0DWa9pCT5n5lDkn4+G8OCbn
+MKnw73bqkHvoIvx4K24On+R5TLoNhEDluYeautJFZafHQjdlIdRk+/Sczti0QbE
YnE4B6VutxPSmorlx/Z46Ev99snFNv0=
=mwMj
-----END PGP SIGNATURE-----