Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion pymongo: issues using $lte and $gte
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Asya Kamsky  
View profile  
 More options Oct 2 2012, 8:56 am
From: Asya Kamsky <a...@10gen.com>
Date: Tue, 2 Oct 2012 05:56:27 -0700 (PDT)
Local: Tues, Oct 2 2012 8:56 am
Subject: Re: pymongo: issues using $lte and $gte

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).

> > list(db.users.find({"produit_up":{"$elemMatch" : {"$gte": 0, "$lte":
> > 100000000}}}, {"_id": 0,"produit_up": {"$elemMatch": {"spec.prix":
> > {"$gte":0,"$lte": 100000000}}}}))

> > 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?

> > > it returns only one element!

> > > list(db.users.find({"produit_up.spec.prix": {"$gte": 0, "$lte":
> > > 100000000}}, {"_id": 0,"produit_up": {"$elemMatch": {"spec.prix":
> > > {"$gte":0,"$lte": 100000000}}}}))

> > > Out[16]:
> > > [{u'produit_up': [{u'avatar': {u'avctype': u'image/jpeg',
> > >      u'orientation': u'portrait',
> > >      u'photo': ObjectId('506867863a5f3a0ea84dcd6c')},
> > >     u'spec': {u'abus': 0,
> > >      u'date': u'2012-09-30',
> > >      u'description': u"portable tr\xe8s solide, peu servi, avec
> > > batterie d'une autonomie de 3 heures.",
> > >      u'id': u'alucaard134901952647',
> > >      u'namep': u'nokia 3310',
> > >      u'nombre': 1,
> > >      u'prix': 1000,
> > >      u'tags': [u'portable', u'nokia', u'3310'],
> > >      u'vendu': False}}]}]

> > > db.users.find({"produit_up.spec.prix": {"$gte": 0, "$lte":
> > > 100000000}}, {"_id": 0,"produit_up": {"$elemMatch": {"spec.prix":
> > > {"$gte":0,"$lte": 100000000}}}}).count()
> > > Out[17]: 1

> > > how do i get the value 3 ?

> > > 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:

> > > > >>> pprint(list(db.users.find({"produit_up.spec.prix": {"$gte": 0,
> > > "$lte": 1000}}, {"_id": 0,"produit_up": {"$elemMatch": {"spec.prix":
> > > {"$gte": 0,"$lte": 1000}}}})))

> > > > [{u'produit_up': [{u'avatar': {u'avctype': u'image/jpeg',
> > > >                                u'orientation': u'portrait',
> > > >                                u'photo':
> > > ObjectId('506867863a5f3a0ea84dcd6c')},
> > > >                    u'spec': {u'abus': 0,
> > > >                              u'date': u'2012-09-30',
> > > >                              u'description': u'test',
> > > >                              u'id': u'alucaard134901952647',
> > > >                              u'namep': u'nokia 3310',
> > > >                              u'nombre': 1,
> > > >                              u'prix': 1000,
> > > >                              u'tags': [u'portable', u'nokia',
> u'3310'],
> > > >                              u'vendu': False}}]}]

> > > > 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

> > > > > list(db.users.find({"produit_up.spec.prix":{"
> $elemMatch":{"$gte":0,
> > > > > "$lte": 1000}}}, {"_id":0,"produit_up":1}))

> > > > > and it returns error!

> > > > > how do i use it?

> > > > > 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:

> > > > >>http://docs.mongodb.org/manual/reference/projection/elemMatch/

> > > > >> 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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.