> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongodb-user@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user+unsubscribe@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb
> > --
> > You received this message because you are subscribed to the Google
> > Groups "mongodb-user" group.
> > To post to this group, send email to mongodb-user@googlegroups.com
> > To unsubscribe from this group, send email to
> > mongodb-user+unsubscribe@googlegroups.com
> > See also the IRC channel -- freenode.net#mongodb
the explication i've is that pymongo make somthing like: verify that a
value that is in that range existe at least in one field, and return
the whole document and not the sub document.
<alabdeloua...@gmail.com> wrote:
> the explication i've is that pymongo make somthing like: verify that a
> value that is in that range existe at least in one field, and return
> the whole document and not the sub document.
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongodb-user@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user+unsubscribe@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb
> On Mon, Oct 1, 2012 at 6:21 AM, aliane abdelouahab
> <alabdeloua...@gmail.com> wrote:
> > the explication i've is that pymongo make somthing like: verify that a
> > value that is in that range existe at least in one field, and return
> > the whole document and not the sub document.
> > --
> > You received this message because you are subscribed to the Google
> > Groups "mongodb-user" group.
> > To post to this group, send email to mongodb-user@googlegroups.com
> > To unsubscribe from this group, send email to
> > mongodb-user+unsubscribe@googlegroups.com
> > See also the IRC channel -- freenode.net#mongodb
You have three values for "produit_up.spec.prix", 1000, 20000, 500000.
Why would you think that {"$gte":0, "$lte": 100} would match any of
those values? 100 is less than all of those values.
The reason that {"$gte":0, "$lte": 1000} returns all three documents
is that they are all subdocuments in an array. Since one of the
subdocuments in the array is matched **the entire enclosing document**
is a match for your query. Since you did a projection on only
"produit_up", just that array (including all array members) is
returned. Use $elemMatch in MongoDB 2.2 to only return the exact
matching array element.
MongoDB and PyMongo are working as designed here.
On Mon, Oct 1, 2012 at 10:58 AM, aliane abdelouahab
<alabdeloua...@gmail.com> wrote:
> but wht the simplest x<value<y dont work?
> i found in lot of examples they use it, so is it deprecated?
> On 1 oct, 15:42, Bernie Hackett <ber...@10gen.com> wrote:
>> PyMongo just sends the query to MongoDB and reads a result, it does
>> not execute the query itself.
>> To get the behavior I think you're asking for see the $elemMatch operator:
>> On Mon, Oct 1, 2012 at 6:21 AM, aliane abdelouahab
>> <alabdeloua...@gmail.com> wrote:
>> > the explication i've is that pymongo make somthing like: verify that a
>> > value that is in that range existe at least in one field, and return
>> > the whole document and not the sub document.
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "mongodb-user" group.
>> > To post to this group, send email to mongodb-user@googlegroups.com
>> > To unsubscribe from this group, send email to
>> > mongodb-user+unsubscribe@googlegroups.com
>> > See also the IRC channel -- freenode.net#mongodb
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongodb-user@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user+unsubscribe@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb
ah! now i understand, it's like using the $ when quering only one
element in a list.
so the old queries speaks always about the root document and not about
the subdocuments!
thank you :)
On 1 oct, 16:13, Bernie Hackett <ber...@10gen.com> wrote:
> You have three values for "produit_up.spec.prix", 1000, 20000, 500000.
> Why would you think that {"$gte":0, "$lte": 100} would match any of
> those values? 100 is less than all of those values.
> The reason that {"$gte":0, "$lte": 1000} returns all three documents
> is that they are all subdocuments in an array. Since one of the
> subdocuments in the array is matched **the entire enclosing document**
> is a match for your query. Since you did a projection on only
> "produit_up", just that array (including all array members) is
> returned. Use $elemMatch in MongoDB 2.2 to only return the exact
> matching array element.
> MongoDB and PyMongo are working as designed here.
> On Mon, Oct 1, 2012 at 10:58 AM, aliane abdelouahab
> <alabdeloua...@gmail.com> wrote:
> > but wht the simplest x<value<y dont work?
> > i found in lot of examples they use it, so is it deprecated?
> > On 1 oct, 15:42, Bernie Hackett <ber...@10gen.com> wrote:
> >> PyMongo just sends the query to MongoDB and reads a result, it does
> >> not execute the query itself.
> >> To get the behavior I think you're asking for see the $elemMatch operator:
> >> On Mon, Oct 1, 2012 at 6:21 AM, aliane abdelouahab
> >> <alabdeloua...@gmail.com> wrote:
> >> > the explication i've is that pymongo make somthing like: verify that a
> >> > value that is in that range existe at least in one field, and return
> >> > the whole document and not the sub document.
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups "mongodb-user" group.
> >> > To post to this group, send email to mongodb-user@googlegroups.com
> >> > To unsubscribe from this group, send email to
> >> > mongodb-user+unsubscribe@googlegroups.com
> >> > See also the IRC channel -- freenode.net#mongodb
> > --
> > You received this message because you are subscribed to the Google
> > Groups "mongodb-user" group.
> > To post to this group, send email to mongodb-user@googlegroups.com
> > To unsubscribe from this group, send email to
> > mongodb-user+unsubscribe@googlegroups.com
> > See also the IRC channel -- freenode.net#mongodb
> On Mon, Oct 1, 2012 at 6:21 AM, aliane abdelouahab
> <alabdeloua...@gmail.com> wrote:
> > the explication i've is that pymongo make somthing like: verify that a
> > value that is in that range existe at least in one field, and return
> > the whole document and not the sub document.
> > --
> > You received this message because you are subscribed to the Google
> > Groups "mongodb-user" group.
> > To post to this group, send email to mongodb-user@googlegroups.com
> > To unsubscribe from this group, send email to
> > mongodb-user+unsubscribe@googlegroups.com
> > See also the IRC channel -- freenode.net#mongodb
<alabdeloua...@gmail.com> wrote:
> here i'm again
> sorry, because i dont know how to use this new $elemMatch when it is
> combined with $gt and $lt ?
> tried this
> On 1 oct, 16:42, Bernie Hackett <ber...@10gen.com> wrote:
>> PyMongo just sends the query to MongoDB and reads a result, it does
>> not execute the query itself.
>> To get the behavior I think you're asking for see the $elemMatch operator:
>> On Mon, Oct 1, 2012 at 6:21 AM, aliane abdelouahab
>> <alabdeloua...@gmail.com> wrote:
>> > the explication i've is that pymongo make somthing like: verify that a
>> > value that is in that range existe at least in one field, and return
>> > the whole document and not the sub document.
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "mongodb-user" group.
>> > To post to this group, send email to mongodb-user@googlegroups.com
>> > To unsubscribe from this group, send email to
>> > mongodb-user+unsubscribe@googlegroups.com
>> > See also the IRC channel -- freenode.net#mongodb
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongodb-user@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user+unsubscribe@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb
> This also requires MongoDB 2.2.x. It will not work in earlier versions.
> On Mon, Oct 1, 2012 at 11:02 AM, aliane abdelouahab
> <alabdeloua...@gmail.com> wrote:
> > here i'm again
> > sorry, because i dont know how to use this new $elemMatch when it is
> > combined with $gt and $lt ?
> > tried this
> > On 1 oct, 16:42, Bernie Hackett <ber...@10gen.com> wrote:
> >> PyMongo just sends the query to MongoDB and reads a result, it does
> >> not execute the query itself.
> >> To get the behavior I think you're asking for see the $elemMatch operator:
> >> On Mon, Oct 1, 2012 at 6:21 AM, aliane abdelouahab
> >> <alabdeloua...@gmail.com> wrote:
> >> > the explication i've is that pymongo make somthing like: verify that a
> >> > value that is in that range existe at least in one field, and return
> >> > the whole document and not the sub document.
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups "mongodb-user" group.
> >> > To post to this group, send email to mongodb-user@googlegroups.com
> >> > To unsubscribe from this group, send email to
> >> > mongodb-user+unsubscribe@googlegroups.com
> >> > See also the IRC channel -- freenode.net#mongodb
> > --
> > You received this message because you are subscribed to the Google
> > Groups "mongodb-user" group.
> > To post to this group, send email to mongodb-user@googlegroups.com
> > To unsubscribe from this group, send email to
> > mongodb-user+unsubscribe@googlegroups.com
> > See also the IRC channel -- freenode.net#mongodb
> This also requires MongoDB 2.2.x. It will not work in earlier versions.
> On Mon, Oct 1, 2012 at 11:02 AM, aliane abdelouahab
> <alabdeloua...@gmail.com> wrote:
> > here i'm again
> > sorry, because i dont know how to use this new $elemMatch when it is
> > combined with $gt and $lt ?
> > tried this
> > On 1 oct, 16:42, Bernie Hackett <ber...@10gen.com> wrote:
> >> PyMongo just sends the query to MongoDB and reads a result, it does
> >> not execute the query itself.
> >> To get the behavior I think you're asking for see the $elemMatch operator:
> >> On Mon, Oct 1, 2012 at 6:21 AM, aliane abdelouahab
> >> <alabdeloua...@gmail.com> wrote:
> >> > the explication i've is that pymongo make somthing like: verify that a
> >> > value that is in that range existe at least in one field, and return
> >> > the whole document and not the sub document.
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups "mongodb-user" group.
> >> > To post to this group, send email to mongodb-user@googlegroups.com
> >> > To unsubscribe from this group, send email to
> >> > mongodb-user+unsubscribe@googlegroups.com
> >> > See also the IRC channel -- freenode.net#mongodb
> > --
> > You received this message because you are subscribed to the Google
> > Groups "mongodb-user" group.
> > To post to this group, send email to mongodb-user@googlegroups.com
> > To unsubscribe from this group, send email to
> > mongodb-user+unsubscribe@googlegroups.com
> > See also the IRC channel -- freenode.net#mongodb
> > This also requires MongoDB 2.2.x. It will not work in earlier versions.
> > On Mon, Oct 1, 2012 at 11:02 AM, aliane abdelouahab
> > <alabdeloua...@gmail.com> wrote: > > > here i'm again > > > sorry, because i dont know how to use this new $elemMatch when it is > > > combined with $gt and $lt ? > > > tried this
> > > On 1 oct, 16:42, Bernie Hackett <ber...@10gen.com> wrote: > > >> PyMongo just sends the query to MongoDB and reads a result, it does > > >> not execute the query itself.
> > >> To get the behavior I think you're asking for see the $elemMatch > operator:
> > >> On Mon, Oct 1, 2012 at 6:21 AM, aliane abdelouahab
> > >> <alabdeloua...@gmail.com> wrote: > > >> > the explication i've is that pymongo make somthing like: verify > that a > > >> > value that is in that range existe at least in one field, and > return > > >> > the whole document and not the sub document.
> > >> > -- > > >> > 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<javascript:> > > >> > To unsubscribe from this group, send email to > > >> > mongodb-user...@googlegroups.com <javascript:> > > >> > See also the IRC channel -- freenode.net#mongodb
> > > -- > > > 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<javascript:> > > > To unsubscribe from this group, send email to > > > mongodb-user...@googlegroups.com <javascript:> > > > See also the IRC channel -- freenode.net#mongodb
> > > This also requires MongoDB 2.2.x. It will not work in earlier versions.
> > > On Mon, Oct 1, 2012 at 11:02 AM, aliane abdelouahab
> > > <alabdeloua...@gmail.com> wrote:
> > > > here i'm again
> > > > sorry, because i dont know how to use this new $elemMatch when it is
> > > > combined with $gt and $lt ?
> > > > tried this
> > > > On 1 oct, 16:42, Bernie Hackett <ber...@10gen.com> wrote:
> > > >> PyMongo just sends the query to MongoDB and reads a result, it does
> > > >> not execute the query itself.
> > > >> To get the behavior I think you're asking for see the $elemMatch
> > operator:
> > > >> On Mon, Oct 1, 2012 at 6:21 AM, aliane abdelouahab
> > > >> <alabdeloua...@gmail.com> wrote:
> > > >> > the explication i've is that pymongo make somthing like: verify
> > that a
> > > >> > value that is in that range existe at least in one field, and
> > return
> > > >> > the whole document and not the sub document.
> > > >> > --
> > > >> > 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<javascript:>
> > > >> > To unsubscribe from this group, send email to
> > > >> > mongodb-user...@googlegroups.com <javascript:>
> > > >> > See also the IRC channel -- freenode.net#mongodb
> > > > --
> > > > 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<javascript:>
> > > > To unsubscribe from this group, send email to
> > > > mongodb-user...@googlegroups.com <javascript:>
> > > > See also the IRC channel -- freenode.net#mongodb
I'm sorry I was responding to part of the last message and not the whole thread.
The point I was trying to make was to make a distinction between $elemMatch for the query part (first JSON document passed to "find") and $elemMatch for projection (second JSON document passed to find).
$elemMatch in the query document is used to match an element of an array in order to select which entire document to return.
$elemMatch in the projection is used to decide which elements of the array of the selected document to display/return to you (rather than returning the entire array with the document).
Asya
P.S. I'll see if I can create an example to illustrate.
Le mardi 2 octobre 2012 08:40:37 UTC-4, aliane abdelouahab a écrit :
> > > > This also requires MongoDB 2.2.x. It will not work in earlier > versions.
> > > > On Mon, Oct 1, 2012 at 11:02 AM, aliane abdelouahab
> > > > <alabdeloua...@gmail.com> wrote: > > > > > here i'm again > > > > > sorry, because i dont know how to use this new $elemMatch when it > is > > > > > combined with $gt and $lt ? > > > > > tried this
> > > > > On 1 oct, 16:42, Bernie Hackett <ber...@10gen.com> wrote: > > > > >> PyMongo just sends the query to MongoDB and reads a result, it > does > > > > >> not execute the query itself.
> > > > >> To get the behavior I think you're asking for see the $elemMatch > > > operator:
> > > > >> On Mon, Oct 1, 2012 at 6:21 AM, aliane abdelouahab
> > > > >> <alabdeloua...@gmail.com> wrote: > > > > >> > the explication i've is that pymongo make somthing like: verify > > > that a > > > > >> > value that is in that range existe at least in one field, and > > > return > > > > >> > the whole document and not the sub document.
> > > > >> > -- > > > > >> > 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<javascript:>
> > > > >> > To unsubscribe from this group, send email to > > > > >> > mongodb-user...@googlegroups.com <javascript:> > > > > >> > See also the IRC channel -- freenode.net#mongodb
> > > > > -- > > > > > 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<javascript:>
> > > > > To unsubscribe from this group, send email to > > > > > mongodb-user...@googlegroups.com <javascript:> > > > > > See also the IRC channel -- freenode.net#mongodb
> I'm sorry I was responding to part of the last message and not the whole
> thread.
> The point I was trying to make was to make a distinction between $elemMatch
> for the query part (first JSON document passed to "find") and $elemMatch
> for projection (second JSON document passed to find).
> $elemMatch in the query document is used to match an element of an array
> in order to select which entire document to return.
> $elemMatch in the projection is used to decide which elements of the array
> of the selected document to display/return to you (rather than returning
> the entire array with the document).
> Asya
> P.S. I'll see if I can create an example to illustrate.
> Le mardi 2 octobre 2012 08:40:37 UTC-4, aliane abdelouahab a écrit :
> > amsorry, but dont get the idea?
> > On 2 oct, 13:33, Asya Kamsky <a...@10gen.com> wrote:
> > > Aliane,
> > > You need to use $elemMatch in the query part (the first JSON document
> > > passed to find).
> > > You probably don't need to use it in the projection part (second JSON
> > > document) if you want the entire array to be returned.
> > > Asya
> > > Le mardi 2 octobre 2012 05:39:39 UTC-4, aliane abdelouahab a écrit :
> > > > the result in only one element? am i doing something wrong? it seems
> > > > that i gets the first element found then exists, do i make a loop?
> > > > On 2 oct, 06:36, Bernie Hackett <ber...@10gen.com> wrote:
> > > > > Reading the docs I linked in my last message
> > > > > (http://docs.mongodb.org/manual/reference/projection/elemMatch/)
> > shows
> > > > > that $elemMatch has to be used in the projection:
> > > > > This also requires MongoDB 2.2.x. It will not work in earlier
> > versions.
> > > > > On Mon, Oct 1, 2012 at 11:02 AM, aliane abdelouahab
> > > > > <alabdeloua...@gmail.com> wrote:
> > > > > > here i'm again
> > > > > > sorry, because i dont know how to use this new $elemMatch when it
> > is
> > > > > > combined with $gt and $lt ?
> > > > > > tried this
> > > > > > On 1 oct, 16:42, Bernie Hackett <ber...@10gen.com> wrote:
> > > > > >> PyMongo just sends the query to MongoDB and reads a result, it
> > does
> > > > > >> not execute the query itself.
> > > > > >> To get the behavior I think you're asking for see the $elemMatch
> > > > operator:
> > > > > >> On Mon, Oct 1, 2012 at 6:21 AM, aliane abdelouahab
> > > > > >> <alabdeloua...@gmail.com> wrote:
> > > > > >> > the explication i've is that pymongo make somthing like: verify
> > > > that a
> > > > > >> > value that is in that range existe at least in one field, and
> > > > return
> > > > > >> > the whole document and not the sub document.
> > > > > >> > --
> > > > > >> > 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<javascript:>
> > > > > >> > To unsubscribe from this group, send email to
> > > > > >> > mongodb-user...@googlegroups.com <javascript:>
> > > > > >> > See also the IRC channel -- freenode.net#mongodb
> > > > > > --
> > > > > > 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<javascript:>
> > > > > > To unsubscribe from this group, send email to
> > > > > > mongodb-user...@googlegroups.com <javascript:>
> > > > > > See also the IRC channel -- freenode.net#mongodb
> sowhy then it dont return all values matched, why only the first value
> then it exits?
> On 2 oct, 13:56, Asya Kamsky <a...@10gen.com> wrote:
> > I'm sorry I was responding to part of the last message and not the whole
> > thread.
> > The point I was trying to make was to make a distinction between
> $elemMatch
> > for the query part (first JSON document passed to "find") and $elemMatch
> > for projection (second JSON document passed to find).
> > $elemMatch in the query document is used to match an element of an array
> > in order to select which entire document to return.
> > $elemMatch in the projection is used to decide which elements of the
> array
> > of the selected document to display/return to you (rather than returning
> > the entire array with the document).
> > Asya
> > P.S. I'll see if I can create an example to illustrate.
> > Le mardi 2 octobre 2012 08:40:37 UTC-4, aliane abdelouahab a écrit :
> > > amsorry, but dont get the idea?
> > > On 2 oct, 13:33, Asya Kamsky <a...@10gen.com> wrote:
> > > > Aliane,
> > > > You need to use $elemMatch in the query part (the first JSON document
> > > > passed to find).
> > > > You probably don't need to use it in the projection part (second JSON
> > > > document) if you want the entire array to be returned.
> > > > Asya
> > > > Le mardi 2 octobre 2012 05:39:39 UTC-4, aliane abdelouahab a écrit :
> > > > > the result in only one element? am i doing something wrong? it
> seems
> > > > > that i gets the first element found then exists, do i make a loop?
> > > > > On 2 oct, 06:36, Bernie Hackett <ber...@10gen.com> wrote:
> > > > > > Reading the docs I linked in my last message
> > > > > > (http://docs.mongodb.org/manual/reference/projection/elemMatch/)
> > > shows
> > > > > > that $elemMatch has to be used in the projection:
> > > > > > This also requires MongoDB 2.2.x. It will not work in earlier
> > > versions.
> > > > > > On Mon, Oct 1, 2012 at 11:02 AM, aliane abdelouahab
> > > > > > <alabdeloua...@gmail.com> wrote:
> > > > > > > here i'm again
> > > > > > > sorry, because i dont know how to use this new $elemMatch when
> it
> > > is
> > > > > > > combined with $gt and $lt ?
> > > > > > > tried this
> > > > > > > On 1 oct, 16:42, Bernie Hackett <ber...@10gen.com> wrote:
> > > > > > >> PyMongo just sends the query to MongoDB and reads a result, it
> > > does
> > > > > > >> not execute the query itself.
> > > > > > >> To get the behavior I think you're asking for see the
> $elemMatch
> > > > > operator:
> > > > > > >> On Mon, Oct 1, 2012 at 6:21 AM, aliane abdelouahab
> > > > > > >> <alabdeloua...@gmail.com> wrote:
> > > > > > >> > the explication i've is that pymongo make somthing like:
> verify
> > > > > that a
> > > > > > >> > value that is in that range existe at least in one field,
> and
> > > > > return
> > > > > > >> > the whole document and not the sub document.
> > > > > > >> > --
> > > > > > >> > 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<javascript:>
> > > > > > >> > To unsubscribe from this group, send email to
> > > > > > >> > mongodb-user...@googlegroups.com <javascript:>
> > > > > > >> > See also the IRC channel -- freenode.net#mongodb
> > > > > > > --
> > > > > > > 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<javascript:>
> > > > > > > To unsubscribe from this group, send email to
> > > > > > > mongodb-user...@googlegroups.com <javascript:>
> > > > > > > See also the IRC channel -- freenode.net#mongodb
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongodb-user@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user+unsubscribe@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb
What? How can price be >50 AND <11??? Well, this document has price=100 and also price=10 (one is >50 and the other is <11).
If you wanted to COMBINE the conditions then you use $elemMatch in the query.
So back to your case - your query was give me all the prod documents where price is greater than 0.
That's all the documents. Also you wanted to match where price was less than some value and that didn't matter because all the documents were already returned.
So you need to use $elemMatch in the query part.
If you then want the entire array returned, then you do not need to use $elemMatch in the projection part.
Asya
Le mardi 2 octobre 2012 09:02:51 UTC-4, aliane abdelouahab a écrit :
> sowhy then it dont return all values matched, why only the first value > then it exits?
> On 2 oct, 13:56, Asya Kamsky <a...@10gen.com> wrote: > > I'm sorry I was responding to part of the last message and not the whole > > thread.
> > The point I was trying to make was to make a distinction between > $elemMatch > > for the query part (first JSON document passed to "find") and $elemMatch > > for projection (second JSON document passed to find).
> > $elemMatch in the query document is used to match an element of an > array > > in order to select which entire document to return. > > $elemMatch in the projection is used to decide which elements of the > array > > of the selected document to display/return to you (rather than returning > > the entire array with the document).
> > Asya > > P.S. I'll see if I can create an example to illustrate.
> > Le mardi 2 octobre 2012 08:40:37 UTC-4, aliane abdelouahab a écrit :
> > > amsorry, but dont get the idea?
> > > On 2 oct, 13:33, Asya Kamsky <a...@10gen.com> wrote: > > > > Aliane,
> > > > You need to use $elemMatch in the query part (the first JSON > document > > > > passed to find).
> > > > You probably don't need to use it in the projection part (second > JSON > > > > document) if you want the entire array to be returned.
> > > > Asya
> > > > Le mardi 2 octobre 2012 05:39:39 UTC-4, aliane abdelouahab a écrit :
> > > > > the result in only one element? am i doing something wrong? it > seems > > > > > that i gets the first element found then exists, do i make a loop?
> > > > > > This also requires MongoDB 2.2.x. It will not work in earlier > > > versions.
> > > > > > On Mon, Oct 1, 2012 at 11:02 AM, aliane abdelouahab
> > > > > > <alabdeloua...@gmail.com> wrote: > > > > > > > here i'm again > > > > > > > sorry, because i dont know how to use this new $elemMatch when > it > > > is > > > > > > > combined with $gt and $lt ? > > > > > > > tried this
> > > > > > >> On Mon, Oct 1, 2012 at 6:21 AM, aliane abdelouahab
> > > > > > >> <alabdeloua...@gmail.com> wrote: > > > > > > >> > the explication i've is that pymongo make somthing like: > verify > > > > > that a > > > > > > >> > value that is in that range existe at least in one field, > and > > > > > return > > > > > > >> > the whole document and not the sub document.
> > > > > > >> > -- > > > > > > >> > 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<javascript:>
> > > > > > >> > To unsubscribe from this group, send email to > > > > > > >> > mongodb-user...@googlegroups.com <javascript:> > > > > > > >> > See also the IRC channel -- freenode.net#mongodb
> > > > > > > -- > > > > > > > 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<javascript:>
> > > > > > > To unsubscribe from this group, send email to > > > > > > > mongodb-user...@googlegroups.com <javascript:> > > > > > > > See also the IRC channel -- freenode.net#mongodb
> What? How can price be >50 AND <11??? Well, this document has price=100
> and also price=10 (one is >50 and the other is <11).
> If you wanted to COMBINE the conditions then you use $elemMatch in the
> query.
> So back to your case - your query was give me all the prod documents where
> price is greater than 0.
> That's all the documents. Also you wanted to match where price was less
> than some value and that didn't matter because all the documents were
> already returned.
> So you need to use $elemMatch in the query part.
> If you then want the entire array returned, then you do not need to use
> $elemMatch in the projection part.
> Asya
> Le mardi 2 octobre 2012 09:02:51 UTC-4, aliane abdelouahab a écrit :
> > sowhy then it dont return all values matched, why only the first value
> > then it exits?
> > On 2 oct, 13:56, Asya Kamsky <a...@10gen.com> wrote:
> > > I'm sorry I was responding to part of the last message and not the whole
> > > thread.
> > > The point I was trying to make was to make a distinction between
> > $elemMatch
> > > for the query part (first JSON document passed to "find") and $elemMatch
> > > for projection (second JSON document passed to find).
> > > $elemMatch in the query document is used to match an element of an
> > array
> > > in order to select which entire document to return.
> > > $elemMatch in the projection is used to decide which elements of the
> > array
> > > of the selected document to display/return to you (rather than returning
> > > the entire array with the document).
> > > Asya
> > > P.S. I'll see if I can create an example to illustrate.
> > > Le mardi 2 octobre 2012 08:40:37 UTC-4, aliane abdelouahab a écrit :
> > > > amsorry, but dont get the idea?
> > > > On 2 oct, 13:33, Asya Kamsky <a...@10gen.com> wrote:
> > > > > Aliane,
> > > > > You need to use $elemMatch in the query part (the first JSON
> > document
> > > > > passed to find).
> > > > > You probably don't need to use it in the projection part (second
> > JSON
> > > > > document) if you want the entire array to be returned.
> > > > > Asya
> > > > > Le mardi 2 octobre 2012 05:39:39 UTC-4, aliane abdelouahab a écrit :
> > > > > > the result in only one element? am i doing something wrong? it
> > seems
> > > > > > that i gets the first element found then exists, do i make a loop?
> > > > > > > This also requires MongoDB 2.2.x. It will not work in earlier
> > > > versions.
> > > > > > > On Mon, Oct 1, 2012 at 11:02 AM, aliane abdelouahab
> > > > > > > <alabdeloua...@gmail.com> wrote:
> > > > > > > > here i'm again
> > > > > > > > sorry, because i dont know how to use this new $elemMatch when
> > it
> > > > is
> > > > > > > > combined with $gt and $lt ?
> > > > > > > > tried this
> > > > > > > >> On Mon, Oct 1, 2012 at 6:21 AM, aliane abdelouahab
> > > > > > > >> <alabdeloua...@gmail.com> wrote:
> > > > > > > >> > the explication i've is that pymongo make somthing like:
> > verify
> > > > > > that a
> > > > > > > >> > value that is in that range existe at least in one field,
> > and
> > > > > > return
> > > > > > > >> > the whole document and not the sub document.
> > > > > > > >> > --
> > > > > > > >> > 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<javascript:>
> > > > > > > >> > To unsubscribe from this group, send email to
> > > > > > > >> > mongodb-user...@googlegroups.com <javascript:>
> > > > > > > >> > See also the IRC channel -- freenode.net#mongodb
> > > > > > > > --
> > > > > > > > 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<javascript:>
> > > > > > > > To unsubscribe from this group, send email to
> > > > > > > > mongodb-user...@googlegroups.com <javascript:>
> > > > > > > > See also the IRC channel -- freenode.net#mongodb
> This is a (quirky) behavioural trait that has been noticed in the
> positional return, that it does only return the first one atm.
> I am not sure exactly why it was made like that however the aggregation
> frameworks $project operator might be able to handle this.
> On 2 October 2012 14:02, aliane abdelouahab <alabdeloua...@gmail.com> wrote:
> > sowhy then it dont return all values matched, why only the first value
> > then it exits?
> > On 2 oct, 13:56, Asya Kamsky <a...@10gen.com> wrote:
> > > I'm sorry I was responding to part of the last message and not the whole
> > > thread.
> > > The point I was trying to make was to make a distinction between
> > $elemMatch
> > > for the query part (first JSON document passed to "find") and $elemMatch
> > > for projection (second JSON document passed to find).
> > > $elemMatch in the query document is used to match an element of an array
> > > in order to select which entire document to return.
> > > $elemMatch in the projection is used to decide which elements of the
> > array
> > > of the selected document to display/return to you (rather than returning
> > > the entire array with the document).
> > > Asya
> > > P.S. I'll see if I can create an example to illustrate.
> > > Le mardi 2 octobre 2012 08:40:37 UTC-4, aliane abdelouahab a écrit :
> > > > amsorry, but dont get the idea?
> > > > On 2 oct, 13:33, Asya Kamsky <a...@10gen.com> wrote:
> > > > > Aliane,
> > > > > You need to use $elemMatch in the query part (the first JSON document
> > > > > passed to find).
> > > > > You probably don't need to use it in the projection part (second JSON
> > > > > document) if you want the entire array to be returned.
> > > > > Asya
> > > > > Le mardi 2 octobre 2012 05:39:39 UTC-4, aliane abdelouahab a écrit :
> > > > > > the result in only one element? am i doing something wrong? it
> > seems
> > > > > > that i gets the first element found then exists, do i make a loop?
> > > > > > On 2 oct, 06:36, Bernie Hackett <ber...@10gen.com> wrote:
> > > > > > > Reading the docs I linked in my last message
> > > > > > > (http://docs.mongodb.org/manual/reference/projection/elemMatch/)
> > > > shows
> > > > > > > that $elemMatch has to be used in the projection:
> > > > > > > This also requires MongoDB 2.2.x. It will not work in earlier
> > > > versions.
> > > > > > > On Mon, Oct 1, 2012 at 11:02 AM, aliane abdelouahab
> > > > > > > <alabdeloua...@gmail.com> wrote:
> > > > > > > > here i'm again
> > > > > > > > sorry, because i dont know how to use this new $elemMatch when
> > it
> > > > is
> > > > > > > > combined with $gt and $lt ?
> > > > > > > > tried this
> > > > > > > >> On Mon, Oct 1, 2012 at 6:21 AM, aliane abdelouahab
> > > > > > > >> <alabdeloua...@gmail.com> wrote:
> > > > > > > >> > the explication i've is that pymongo make somthing like:
> > verify
> > > > > > that a
> > > > > > > >> > value that is in that range existe at least in one field,
> > and
> > > > > > return
> > > > > > > >> > the whole document and not the sub document.
> > > > > > > >> > --
> > > > > > > >> > 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<javascript:>
> > > > > > > >> > To unsubscribe from this group, send email to
> > > > > > > >> > mongodb-user...@googlegroups.com <javascript:>
> > > > > > > >> > See also the IRC channel -- freenode.net#mongodb
> > > > > > > > --
> > > > > > > > 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<javascript:>
> > > > > > > > To unsubscribe from this group, send email to
> > > > > > > > mongodb-user...@googlegroups.com <javascript:>
> > > > > > > > See also the IRC channel -- freenode.net#mongodb
> > --
> > You received this message because you are subscribed to the Google
> > Groups "mongodb-user" group.
> > To post to this group, send email to mongodb-user@googlegroups.com
> > To unsubscribe from this group, send email to
> > mongodb-user+unsubscribe@googlegroups.com
> > See also the IRC channel -- freenode.net#mongodb
You would then use $elemMatch in the find clause *and* use $elemMatch in the projection clause.
Do you really need to include $gt:0 ? I would think that the price is always greater than 0, no?
Continuing building on my example though:
// changing the condition to something reasonable, price between 50 and 110
db.em2.find({"prod":{$elemMatch:{price:{$gt:50,$lt:110}}}})
{ "_id" : 1, "prod" : [ { "price" : 10 }, { "price" : 100 } ] }
// use projection to only get back price array
db.em2.find({"prod":{$elemMatch:{price:{$gt:50,$lt:110}}}},{_id:0, prod:1})
{ "prod" : [ { "price" : 10 }, { "price" : 100 } ] }
// use projection to only get back price array element that matches the condition passed. NOTE: only the first matching array element would be returned
db.em2.find({"prod":{$elemMatch:{price:{$gt:50,$lt:110}}}},{_id:0, prod:{$elemMatch:{price:{$gt:50,$lt:110}}}})
{ "prod" : [ { "price" : 100 } ] }
> > What? How can price be >50 AND <11??? Well, this document has > price=100 > > and also price=10 (one is >50 and the other is <11). > > If you wanted to COMBINE the conditions then you use $elemMatch in the > > query.
> > So back to your case - your query was give me all the prod documents > where > > price is greater than 0.
> > That's all the documents. Also you wanted to match where price was > less > > than some value and that didn't matter because all the documents were > > already returned.
> > So you need to use $elemMatch in the query part. > > If you then want the entire array returned, then you do not need to use > > $elemMatch in the projection part.
> > Asya
> > Le mardi 2 octobre 2012 09:02:51 UTC-4, aliane abdelouahab a écrit :
> > > sowhy then it dont return all values matched, why only the first value > > > then it exits?
> > > On 2 oct, 13:56, Asya Kamsky <a...@10gen.com> wrote: > > > > I'm sorry I was responding to part of the last message and not the > whole > > > > thread.
> > > > The point I was trying to make was to make a distinction between > > > $elemMatch > > > > for the query part (first JSON document passed to "find") and > $elemMatch > > > > for projection (second JSON document passed to find).
> > > > $elemMatch in the query document is used to match an element of an > > > array > > > > in order to select which entire document to return. > > > > $elemMatch in the projection is used to decide which elements of > the > > > array > > > > of the selected document to display/return to you (rather than > returning > > > > the entire array with the document).
> > > > Asya > > > > P.S. I'll see if I can create an example to illustrate.
> > > > Le mardi 2 octobre 2012 08:40:37 UTC-4, aliane abdelouahab a écrit :
> > > > > amsorry, but dont get the idea?
> > > > > On 2 oct, 13:33, Asya Kamsky <a...@10gen.com> wrote: > > > > > > Aliane,
> > > > > > You need to use $elemMatch in the query part (the first JSON > > > document > > > > > > passed to find).
> > > > > > You probably don't need to use it in the projection part (second > > > JSON > > > > > > document) if you want the entire array to be returned.
> > > > > > Asya
> > > > > > Le mardi 2 octobre 2012 05:39:39 UTC-4, aliane abdelouahab a > écrit :
> > > > > > > the result in only one element? am i doing something wrong? it > > > seems > > > > > > > that i gets the first element found then exists, do i make a > loop?
> > > > > > > > This also requires MongoDB 2.2.x. It will not work in > earlier > > > > > versions.
> > > > > > > > On Mon, Oct 1, 2012 at 11:02 AM, aliane abdelouahab
> > > > > > > > <alabdeloua...@gmail.com> wrote: > > > > > > > > > here i'm again > > > > > > > > > sorry, because i dont know how to use this new $elemMatch > when > > > it > > > > > is > > > > > > > > > combined with $gt and $lt ? > > > > > > > > > tried this
> > > > > > > > >> On Mon, Oct 1, 2012 at 6:21 AM, aliane abdelouahab
> > > > > > > > >> <alabdeloua...@gmail.com> wrote: > > > > > > > > >> > the explication i've is that pymongo make somthing > like: > > > verify > > > > > > > that a > > > > > > > > >> > value that is in that range existe at least in one > field, > > > and > > > > > > > return > > > > > > > > >> > the whole document and not the sub document.
> > > > > > > > >> > -- > > > > > > > > >> > You received this message because you are subscribed to > the > > > > > Google > > > > > > > > >> > Groups "mongodb-user" group. > > > > > > > > >> > To post to this group, send
about using the zero value, it's just to see if there is not bug, it's
something like debugging (if the whole expression is evaluated).
am sorry, if i dont get the idea clearly, why not making an iterator
for the elementMatch?
On 2 oct, 16:15, Asya Kamsky <a...@10gen.com> wrote:
> You would then use $elemMatch in the find clause *and* use $elemMatch in
> the projection clause.
> Do you really need to include $gt:0 ? I would think that the price is
> always greater than 0, no?
> Continuing building on my example though:
> // changing the condition to something reasonable, price between 50 and 110
> db.em2.find({"prod":{$elemMatch:{price:{$gt:50,$lt:110}}}})
> { "_id" : 1, "prod" : [ { "price" : 10 }, { "price" : 100 } ] }
> // use projection to only get back price array
> db.em2.find({"prod":{$elemMatch:{price:{$gt:50,$lt:110}}}},{_id:0, prod:1})
> { "prod" : [ { "price" : 10 }, { "price" : 100 } ] }
> // use projection to only get back price array element that matches the
> condition passed. NOTE: only the first matching array element would be
> returned
> db.em2.find({"prod":{$elemMatch:{price:{$gt:50,$lt:110}}}},{_id:0,
> prod:{$elemMatch:{price:{$gt:50,$lt:110}}}})
> { "prod" : [ { "price" : 100 } ] }
> Asya
> On Tuesday, October 2, 2012 11:08:51 AM UTC-4, aliane abdelouahab wrote:
> > so how to make a solution to show me the number of mathed products
> > that are between max and min?
> > On 2 oct, 14:35, Asya Kamsky <a...@10gen.com> wrote:
> > > It's possible that something got lost in the discussion :)
> > > If you want it to return the entire array, simply don't use $elemMatch
> > in
> > > your projection.
> > > What? How can price be >50 AND <11??? Well, this document has
> > price=100
> > > and also price=10 (one is >50 and the other is <11).
> > > If you wanted to COMBINE the conditions then you use $elemMatch in the
> > > query.
> > > So back to your case - your query was give me all the prod documents
> > where
> > > price is greater than 0.
> > > That's all the documents. Also you wanted to match where price was
> > less
> > > than some value and that didn't matter because all the documents were
> > > already returned.
> > > So you need to use $elemMatch in the query part.
> > > If you then want the entire array returned, then you do not need to use
> > > $elemMatch in the projection part.
> > > Asya
> > > Le mardi 2 octobre 2012 09:02:51 UTC-4, aliane abdelouahab a écrit :
> > > > sowhy then it dont return all values matched, why only the first value
> > > > then it exits?
> > > > On 2 oct, 13:56, Asya Kamsky <a...@10gen.com> wrote:
> > > > > I'm sorry I was responding to part of the last message and not the
> > whole
> > > > > thread.
> > > > > The point I was trying to make was to make a distinction between
> > > > $elemMatch
> > > > > for the query part (first JSON document passed to "find") and
> > $elemMatch
> > > > > for projection (second JSON document passed to find).
> > > > > $elemMatch in the query document is used to match an element of an
> > > > array
> > > > > in order to select which entire document to return.
> > > > > $elemMatch in the projection is used to decide which elements of
> > the
> > > > array
> > > > > of the selected document to display/return to you (rather than
> > returning
> > > > > the entire array with the document).
> > > > > Asya
> > > > > P.S. I'll see if I can create an example to illustrate.
> > > > > Le mardi 2 octobre 2012 08:40:37 UTC-4, aliane abdelouahab a écrit :
> > > > > > > You probably don't need to use it in the projection part (second
> > > > JSON
> > > > > > > document) if you want the entire array to be returned.
> > > > > > > Asya
> > > > > > > Le mardi 2 octobre 2012 05:39:39 UTC-4, aliane abdelouahab a
> > écrit :
> > > > > > > > the result in only one element? am i doing something wrong? it
> > > > seems
> > > > > > > > that i gets the first element found then exists, do i make a
> > loop?