find([spec=None[, fields=None[, skip=0[, limit=0[, timeout=True[, snapshot=False[, tailable=False[, sort=None[, max_scan=None[, as_class=None[, **kwargs]]]]]]]]]]]) >>> db.test.find({"hello": "world"}) ??
--
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.
Note: A negative limit tell the server to return that number (or what
fits in a response), and closes the cursor immediately.
I have the following:
-------------
for entries in blog.entry.find().sort("edits.written", pymongo.DESCENDING):
print entries['title']
entry = blog.entry.find_one().sort("edits.written")
print entry
-------------
I get:
-------------
[________@_____ www]$ python test.py
So, this is the first real post on my new blog...
30 Days of Writing
30 Days of Writing, Day 1
30 Days of Writing, Day 2
30 Days of Writing, Day 3
30 Days of Writing, Day 4
Potential Web Development Contracting
30 Days of Writing, Day 5
30 Days of Writing, Day 6
30 Days of Writing, Day 7
30 Days of Writing, Day 8
30 Days of Writing, Day 9
What's up with that, NASA?
30 Days of Writing, Day 10
30 Days of Writing, Day 11
30 Days of Writing, Day 12
30 Days of Writing, Day 13
30 Days of Writing, Day 14
30 Days of Writing, Day 15
Switching over to MongoDB
Traceback (most recent call last):
File "test.py", line 12, in <module>
entry = blog.entry.find_one().sort("edits.written")
AttributeError: 'dict' object has no attribute 'sort'
-------------
... now, oddly... when i do pymongo.ASCENDING or DESCENDING on another
field (category or zone for example) they correctly reverse directions.
However, if I use it on the datetime field there, it pretends to work,
but they're always in ascending order either way. That's another
question, I suppose.
for now, though, find_one() appears to have dereferenced the sole
result, by which point it is too late to sort on it. So it seems I need
to have a means of doing the sort within the (), and I've not had any
success finding an example of that for either .find() or .find_one().
*fail*
Taking a hint from Dwight Merriman's mongo command line version:
-------------
for entries in blog.entry.find().sort("edits.written",
pymongo.DESCENDING).limit(1):
print entries['title']
-------------
I do get a sole result, but it's still ignoring the sort when sorting
against a date. =( I know I'll eventually want to create an index on
that field of that subdocument (gee, I hope I can, come to think of it);
setting it to descending may force this the other way? (i shall
experiment, since I've already had to un-port to do my daily blogging
which means a new re-port tomorrow for hair-whitening exercises.)
~jet
--
LEGAL NOTICE: The information in this transmission may contain privileged and confidential information. It is intended only for the use of the person(s) named above. If you are the intended recipient, you are hereby notified that any review, dissemination, distribution, or duplication of this communication is strictly prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.