[mongodb-user] Mongodb capped collections sort natural order or reverse order bug

223 views
Skip to first unread message

paul jobs

unread,
Apr 26, 2010, 12:52:31 AM4/26/10
to mongod...@googlegroups.com
Hey Guys
 i tried to sort
for s in mongodb.cappedcol.find().sort({'$natural':-1,'kw':1},-1)

but i get the following error

first item in each key pair must be a string

i also tried

Have you see this erro
r -> If yes Please let me know how to fix this or get the capped collection toreturn the items in newest first order
for s in mongodb.cappedcol.find().sort({'$natural':-1},-1)

Thanks a lot
--
Amazing wedding entrance viral video
http://bit.ly/9a12pd

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

Eliot Horowitz

unread,
Apr 26, 2010, 12:55:06 AM4/26/10
to mongod...@googlegroups.com
What driver are you using?
I think you just want
mongodb.cappedcol.find().sort({'$natural':-1})
but hard to tell if in shell or python

paul jobs

unread,
Apr 26, 2010, 1:22:41 AM4/26/10
to mongod...@googlegroups.com
so the driver is pymongo

i tried 
mongodb.cappedcol.find().sort({'$natural':-1})



but this gives an error too 
/home/mark/<ipython console> in <module>()

/usr/lib/python2.5/site-packages/pymongo-1.5.2-py2.5-linux-x86_64.egg/pymongo/cursor.pyc in sort(self, key_or_list, direction)
    277         """
    278         self.__check_okay_to_chain()
--> 279         keys = helpers._index_list(key_or_list, direction)
    280         self.__ordering = helpers._index_document(keys)
    281         return self

/usr/lib/python2.5/site-packages/pymongo-1.5.2-py2.5-linux-x86_64.egg/pymongo/helpers.pyc in _index_list(key_or_list, direction)
     42             return [(key_or_list, pymongo.ASCENDING)]
     43         elif not isinstance(key_or_list, list):
---> 44             raise TypeError("if no direction is specified, "
     45                             "key_or_list must be an instance of list")
     46         return key_or_list

TypeError: if no direction is specified, key_or_list must be an instance of list

Eliot Horowitz

unread,
Apr 26, 2010, 1:26:15 AM4/26/10
to mongod...@googlegroups.com
I think youre using shell sort syntax in python

Make sure you look at the python sort docs 

paul jobs

unread,
Apr 26, 2010, 1:37:52 PM4/26/10
to mongod...@googlegroups.com
{% for s in mongodb.cappedcol.find().sort('$natural',pymongo.DESCENDING) %}

this works

as does

{% for s in mongodb.cappedcol.find().sort('$natural',-1) %}

as does
{% for s in mongodb.cappedcol.find().sort('natural',-1) %}

what is the difference between $natural and natural

Flaper87

unread,
Apr 26, 2010, 3:06:57 PM4/26/10
to mongod...@googlegroups.com
Hi Paul,

You should take a look here[0]


btw, all mongodb keywords have a $ ;)

bye.

2010/4/26 paul jobs <webj...@gmail.com>



--
Flavio Percoco Premoli, A.K.A. [Flaper87]
http://www.flaper87.org
Usuario Linux registrado #436538
Geek by nature, Linux by choice, Archer of course.
Key Fingerprint: CFC0 C67D FF73 463B 7E55  CF43 25D1 E75B E2DB 15C7
The Solution to everything:
python -c "from struct import pack; print  pack('5b', (41*len('99')), pow(8,2)+20, 4900**0.5, range(78)[-1], 10)"
Reply all
Reply to author
Forward
0 new messages