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
pymongo: issues using $lte and $gte
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 32 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
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
 
aliane abdelouahab  
View profile   Translate to Translated (View Original)
 More options Sep 30 2012, 1:59 pm
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Sun, 30 Sep 2012 10:59:00 -0700 (PDT)
Subject: pymongo: issues using $lte and $gte
hi, it seems that:

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

and

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

give the same result (in the logic, it will give only one result, we
have three values: 1000, 20000, 500000):

[{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}},
   {u'avatar': {u'avctype': u'image/jpeg',
     u'orientation': u'portrait',
     u'photo': ObjectId('50686d013a5f3a04a8923b3e')},
    u'spec': {u'abus': 0,
     u'date': u'2012-09-30',
     u'description': u'test',
     u'namep': u'iphone 3gs',
     u'nombre': 1,
     u'prix': 20000,
     u'tags': [u'iphone', u'3gs', u'apple'],
     u'vendu': False}},
   {u'avatar': {u'avctype': u'image/jpeg',
     u'orientation': u'paysage',
     u'photo': ObjectId('50686d3e3a5f3a04a8923b40')},
    u'spec': {u'abus': 0,
     u'date': u'2012-09-30',
     u'description': u'test',
     u'id': u'alucaard134902099082',
     u'namep': u'peugeot 206',
     u'nombre': 1,
     u'prix': 500000,
     u'tags': [u'voiture', u'206', u'hdi'],
     u'vendu': False}}]}]


 
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.
Bernie Hackett  
View profile  
 More options Sep 30 2012, 2:15 pm
From: Bernie Hackett <ber...@10gen.com>
Date: Sun, 30 Sep 2012 14:14:56 -0400
Local: Sun, Sep 30 2012 2:14 pm
Subject: Re: [mongodb-user] pymongo: issues using $lte and $gte
>>> list(db.users.find({"produit_up.spec.prix":{"$gte":0, "$lte": 1000000}}, {"_id":0,"produit_up":1}))

[{u'produit_up': {u'spec': {u'prix': 1000}}}, {u'produit_up':
{u'spec': {u'prix': 20000}}}, {u'produit_up': {u'spec': {u'prix':
500000}}}]

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

[{u'produit_up': {u'spec': {u'prix': 1000}}}]

Looks correct to me. What do you get?

On Sun, Sep 30, 2012 at 1:59 PM, aliane abdelouahab


 
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.
aliane abdelouahab  
View profile  
 More options Sep 30 2012, 5:39 pm
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Sun, 30 Sep 2012 14:38:49 -0700 (PDT)
Local: Sun, Sep 30 2012 5:38 pm
Subject: Re: pymongo: issues using $lte and $gte
i'll check this (ive no internet connexion at home, so i just copy the
code now and i try it..) but have never seen this tip before :o

On 30 sep, 19:15, Bernie Hackett <ber...@10gen.com> wrote:


 
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.
aliane abdelouahab  
View profile  
 More options Oct 1 2012, 5:54 am
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Mon, 1 Oct 2012 02:53:59 -0700 (PDT)
Local: Mon, Oct 1 2012 5:53 am
Subject: Re: pymongo: issues using $lte and $gte
am still getting the same result!
it's like mongodb dont get the numbers! it worls only when using a
value that is smaller than the upper value!

i'm using Mongodb 2.2 64bits on win7, driver: latest pymongo.


 
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.
aliane abdelouahab  
View profile  
 More options Oct 1 2012, 6:00 am
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Mon, 1 Oct 2012 03:00:31 -0700 (PDT)
Local: Mon, Oct 1 2012 6:00 am
Subject: Re: pymongo: issues using $lte and $gte
list(db.users.find({"produit_up.spec.prix":{"$gte":0, "$lte": 1000}},
{"_id":0,"produit_up":1}))
Out[5]:
[{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}},
   {u'avatar': {u'avctype': u'image/jpeg',
     u'orientation': u'portrait',
     u'photo': ObjectId('50686d013a5f3a04a8923b3e')},
    u'spec': {u'abus': 0,
     u'date': u'2012-09-30',
     u'description': u'\u0646\u0628\u064a\u0639 \u0623\u064a
\u0641\u0648\u0646 \u062c\u062f\u064a\u062f \u0641\u064a
\u0627\u0644\u0628\u0648\u0627\u0637 \u0645\u0639\u0627\u0647
\u0634\u0627\u0631\u062c\u0648\u0631 \u062f\u0648\u0631\u064a\u062c
\u064a\u0646',
     u'id': u'alucaard134902092967',
     u'namep': u'iphone 3gs',
     u'nombre': 1,
     u'prix': 20000,
     u'tags': [u'iphone', u'3gs', u'apple'],
     u'vendu': False}},
   {u'avatar': {u'avctype': u'image/jpeg',
     u'orientation': u'paysage',
     u'photo': ObjectId('50686d3e3a5f3a04a8923b40')},
    u'spec': {u'abus': 0,
     u'date': u'2012-09-30',
     u'description': u'vends 206 toutes options 2006 hdi.',
     u'id': u'alucaard134902099082',
     u'namep': u'peugeot 206',
     u'nombre': 1,
     u'prix': 500000,
     u'tags': [u'voiture', u'206', u'hdi'],
     u'vendu': False}}]}]

list(db.users.find({"produit_up.spec.prix":{"$gte":0, "$lte": 100}},
{"_id":0,"produit_up":1}))
Out[6]: []

pymongo.version
Out[8]: '2.3+'


 
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.
aliane abdelouahab  
View profile  
 More options Oct 1 2012, 6:17 am
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Mon, 1 Oct 2012 03:16:56 -0700 (PDT)
Local: Mon, Oct 1 2012 6:16 am
Subject: Re: pymongo: issues using $lte and $gte
it's not the driver's issue, it's mongodb, am in the shell and gives
me the same result!

db.version()
2.2.0


 
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.
aliane abdelouahab  
View profile  
 More options Oct 1 2012, 6:21 am
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Mon, 1 Oct 2012 03:21:17 -0700 (PDT)
Local: Mon, Oct 1 2012 6:21 am
Subject: Re: pymongo: issues using $lte and $gte
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 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.
Bernie Hackett  
View profile  
 More options Oct 1 2012, 10:42 am
From: Bernie Hackett <ber...@10gen.com>
Date: Mon, 1 Oct 2012 10:41:45 -0400
Local: Mon, Oct 1 2012 10:41 am
Subject: Re: [mongodb-user] Re: pymongo: issues using $lte and $gte
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


 
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.
aliane abdelouahab  
View profile  
 More options Oct 1 2012, 10:58 am
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Mon, 1 Oct 2012 07:58:24 -0700 (PDT)
Local: Mon, Oct 1 2012 10:58 am
Subject: Re: pymongo: issues using $lte and $gte
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:


 
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.
Bernie Hackett  
View profile  
 More options Oct 1 2012, 11:13 am
From: Bernie Hackett <ber...@10gen.com>
Date: Mon, 1 Oct 2012 11:13:33 -0400
Local: Mon, Oct 1 2012 11:13 am
Subject: Re: [mongodb-user] Re: pymongo: issues using $lte and $gte
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


 
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.
aliane abdelouahab  
View profile  
 More options Oct 1 2012, 11:23 am
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Mon, 1 Oct 2012 08:22:55 -0700 (PDT)
Local: Mon, Oct 1 2012 11:22 am
Subject: Re: pymongo: issues using $lte and $gte
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 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.
aliane abdelouahab  
View profile  
 More options Oct 1 2012, 2:03 pm
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Mon, 1 Oct 2012 11:02:49 -0700 (PDT)
Local: Mon, Oct 1 2012 2:02 pm
Subject: Re: pymongo: issues using $lte and $gte
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:


 
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.
Bernie Hackett  
View profile  
 More options Oct 2 2012, 1:36 am
From: Bernie Hackett <ber...@10gen.com>
Date: Mon, 1 Oct 2012 22:36:12 -0700
Local: Tues, Oct 2 2012 1:36 am
Subject: Re: [mongodb-user] Re: pymongo: issues using $lte and $gte
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


 
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.
aliane abdelouahab  
View profile  
 More options Oct 2 2012, 5:02 am
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Tue, 2 Oct 2012 02:02:28 -0700 (PDT)
Local: Tues, Oct 2 2012 5:02 am
Subject: Re: pymongo: issues using $lte and $gte
thank you very much :D
am sorry because i've not passed the SQL word to understand the
projection :p

On 2 oct, 06:36, Bernie Hackett <ber...@10gen.com> wrote:


 
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.
aliane abdelouahab  
View profile  
 More options Oct 2 2012, 5:39 am
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Tue, 2 Oct 2012 02:39:29 -0700 (PDT)
Local: Tues, Oct 2 2012 5:39 am
Subject: Re: pymongo: issues using $lte and $gte
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:


 
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.
Asya Kamsky  
View profile  
 More options Oct 2 2012, 8:33 am
From: Asya Kamsky <a...@10gen.com>
Date: Tue, 2 Oct 2012 05:33:47 -0700 (PDT)
Local: Tues, Oct 2 2012 8:33 am
Subject: Re: pymongo: issues using $lte and $gte

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 :


 
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.
aliane abdelouahab  
View profile  
 More options Oct 2 2012, 8:40 am
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Tue, 2 Oct 2012 05:40:27 -0700 (PDT)
Local: Tues, Oct 2 2012 8:40 am
Subject: Re: pymongo: issues using $lte and $gte
amsorry, but dont get the idea?

On 2 oct, 13:33, Asya Kamsky <a...@10gen.com> wrote:


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


 
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.
aliane abdelouahab  
View profile  
 More options Oct 2 2012, 9:02 am
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Tue, 2 Oct 2012 06:02:40 -0700 (PDT)
Local: Tues, Oct 2 2012 9:02 am
Subject: Re: pymongo: issues using $lte and $gte
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:


 
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.
Sam Millman  
View profile  
 More options Oct 2 2012, 9:20 am
From: Sam Millman <sam.mill...@gmail.com>
Date: Tue, 2 Oct 2012 14:20:37 +0100
Local: Tues, Oct 2 2012 9:20 am
Subject: Re: [mongodb-user] Re: pymongo: issues using $lte and $gte

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:


 
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.
Asya Kamsky  
View profile  
 More options Oct 2 2012, 9:35 am
From: Asya Kamsky <a...@10gen.com>
Date: Tue, 2 Oct 2012 06:35:27 -0700 (PDT)
Local: Tues, Oct 2 2012 9:35 am
Subject: Re: pymongo: issues using $lte and $gte

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.

Your original query was:

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

I think you originally got the answer about why all prices were returned
and not just the ones that matched your condition(s).

But I think you asking about why a document was returned when it didn't
SEEM  to match the condition(s) you were passing?

Example:

db.em2.find().pretty()
{
"_id" : 1,
"prod" : [
{
"price" : 10

},

{
"price" : 100

}
]
}

db.em2.find({"prod.price":{$gt:50}})
{ "_id" : 1, "prod" : [ { "price" : 10 }, { "price" : 100 } ] }

BUT
db.em2.find({"prod.price":{$gt:50,$lt:11}})
{ "_id" : 1, "prod" : [ { "price" : 10 }, { "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.

db.em2.find({"prod":{$elemMatch:{price:{$gt:50,$lt:11}}}})
(nothing returned)

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 :


 
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.
aliane abdelouahab  
View profile  
 More options Oct 2 2012, 11:08 am
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Tue, 2 Oct 2012 08:08:37 -0700 (PDT)
Local: Tues, Oct 2 2012 11:08 am
Subject: Re: pymongo: issues using $lte and $gte
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:


 
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.
aliane abdelouahab  
View profile  
 More options Oct 2 2012, 11:09 am
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Tue, 2 Oct 2012 08:09:42 -0700 (PDT)
Local: Tues, Oct 2 2012 11:09 am
Subject: Re: pymongo: issues using $lte and $gte
can you please provide me the way to do it? and this will take a lot
of time if i'll use a blocking query?

On 2 oct, 14:20, Sam Millman <sam.mill...@gmail.com> wrote:


 
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.
Asya Kamsky  
View profile  
 More options Oct 2 2012, 11:15 am
From: Asya Kamsky <a...@10gen.com>
Date: Tue, 2 Oct 2012 08:15:05 -0700 (PDT)
Local: Tues, Oct 2 2012 11:15 am
Subject: Re: pymongo: issues using $lte and $gte

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

...

read more »


 
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.
aliane abdelouahab  
View profile  
 More options Oct 2 2012, 11:21 am
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Tue, 2 Oct 2012 08:21:28 -0700 (PDT)
Local: Tues, Oct 2 2012 11:21 am
Subject: Re: pymongo: issues using $lte and $gte
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:

...

read more »


 
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.
Messages 1 - 25 of 32   Newer >
« Back to Discussions « Newer topic     Older topic »