Message from discussion
pymongo find_and_modify not honoring sort?
Received: by 10.42.158.4 with SMTP id f4mr3185288icx.4.1323928670238;
Wed, 14 Dec 2011 21:57:50 -0800 (PST)
X-BeenThere: mongodb-user@googlegroups.com
Received: by 10.231.11.72 with SMTP id s8ls6102447ibs.3.gmail; Wed, 14 Dec
2011 21:57:39 -0800 (PST)
Received: by 10.42.159.3 with SMTP id j3mr3109726icx.8.1323928658854;
Wed, 14 Dec 2011 21:57:38 -0800 (PST)
Received: by 10.42.159.3 with SMTP id j3mr3109725icx.8.1323928658844;
Wed, 14 Dec 2011 21:57:38 -0800 (PST)
Return-Path: <zacwi...@gmail.com>
Received: from mail-iy0-f185.google.com (mail-iy0-f185.google.com [209.85.210.185])
by gmr-mx.google.com with ESMTPS id h7si1674141icn.2.2011.12.14.21.57.38
(version=TLSv1/SSLv3 cipher=OTHER);
Wed, 14 Dec 2011 21:57:38 -0800 (PST)
Received-SPF: pass (google.com: domain of zacwi...@gmail.com designates 209.85.210.185 as permitted sender) client-ip=209.85.210.185;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of zacwi...@gmail.com designates 209.85.210.185 as permitted sender) smtp.mail=zacwi...@gmail.com
Received: by iafj26 with SMTP id j26so2327777iaf.12
for <mongodb-user@googlegroups.com>; Wed, 14 Dec 2011 21:57:38 -0800 (PST)
MIME-Version: 1.0
Received: by 10.50.185.201 with SMTP id fe9mr296313igc.20.1323928658779; Wed,
14 Dec 2011 21:57:38 -0800 (PST)
Received: by y39g2000prf.googlegroups.com with HTTP; Wed, 14 Dec 2011 21:57:38
-0800 (PST)
Date: Wed, 14 Dec 2011 21:57:38 -0800 (PST)
In-Reply-To: <2d6eb971-b460-41a5-9826-944523af3689@n22g2000prh.googlegroups.com>
References: <d459852f-ec2b-416a-9d51-3a224072afa1@f36g2000prj.googlegroups.com>
<2d6eb971-b460-41a5-9826-944523af3689@n22g2000prh.googlegroups.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2)
AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2,gzip(gfe)
Message-ID: <e814caef-0b50-477c-a98a-43b894b296af@y39g2000prf.googlegroups.com>
Subject: Re: pymongo find_and_modify not honoring sort?
From: Zac Witte <zacwi...@gmail.com>
To: mongodb-user <mongodb-user@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Thanks Bernie, that did the trick. I think the documentation could use
some fixing, since there's no indication of a different syntax from
the find command and there's no OperationFailure thrown when the wrong
parameter is supplied.
Zac
On Dec 14, 8:48=A0pm, Bernie Hackett <ber...@10gen.com> wrote:
> sort=3D{'file_name': ASCENDING} will work.
>
> On Dec 14, 4:21=A0pm, Zac Witte <zacwi...@gmail.com> wrote:
>
>
>
>
>
>
>
> > I'm I missing something here?
>
> > ubuntu@mongo1:~/pubnub-analytics$ python
> > Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
> > [GCC 4.5.2] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.>=
>> from pymongo import Connection
> > >>> from pymongo import ASCENDING, DESCENDING
> > >>> conn =3D Connection()
> > >>> db =3D conn.pb2
> > >>> db.log_files.find_and_modify(
>
> > ... =A0 =A0 query=3D{'status':'unprocessed'},
> > ... =A0 =A0 update=3D{'$set':{}},
> > ... =A0 =A0 sort=3D[('file_name',ASCENDING)],
> > ... =A0 =A0 new=3DTrue)
> > {u'status': u'unprocessed', u'file_name':
> > u'2011-12-03_23:04:34.288091_50.18.36.76.log.bz2', u'_id':
> > ObjectId('4ee805931d011c644f003260')}>>> db.log_files.find_one({'status=
':'unprocessed'})
>
> > {u'status': u'unprocessed', u'file_name':
> > u'2011-12-03_23:04:34.288091_50.18.36.76.log.bz2', u'_id':
> > ObjectId('4ee805931d011c644f003260')}>>> db.log_files.find_one({'status=
':'unprocessed'}, sort=3D[('file_name',ASCENDING)])
>
> > {u'status': u'unprocessed', u'file_name':
> > u'2011-09-30_10:48:23.843037_46.137.255.217.log', u'_id':
> > ObjectId('4ee805981d011c644f00916c'), u'end_time':
> > datetime.datetime(2011, 12, 14, 2, 35, 52, 160000)}