inserting dates using REST

195 views
Skip to first unread message

D-Rep

unread,
Dec 4, 2010, 1:00:38 PM12/4/10
to mongodb-user
I'm using Sleepy Mongoose to try and insert a new document with a
date, and am having trouble with the syntax. I'm trying to figure out
how to translate this shell command:
db.testing.insert({"created_date": new Date("12/04/2010")});


# no quotes around $date - says that its not valid JSON (as expected)
$ curl -X POST --data 'docs=[{"created_date": {$date:
1291438800000}}]' http://localhost:27080/personal/testing/_insert

# Would expect this to work, but it says: key '$date' must not start
with '$'
$ curl -X POST --data 'docs=[{"created_date": {"$date":
1291438800000}}]' http://localhost:27080/personal/testing/_insert

# encode the dollar sign gives same error
$ curl -X POST --data 'docs=[{"created_date": {"%24date":
1291438800000}}]' http://localhost:27080/personal/testing/_insert



This is the stack trace from Sleepy Mongoose...
File "/usr/local/share/mongodb/sleepy.mongoose/httpd.py", line 189,
in do_POST
self.call_handler(uri, args)
File "/usr/local/share/mongodb/sleepy.mongoose/httpd.py", line 112,
in call_handler
func(args, self.wfile.write, name = name, db = db, collection =
collection)
File "/usr/local/share/mongodb/sleepy.mongoose/handlers.py", line
328, in _insert
result = {}
File "/usr/local/lib/python2.6/dist-packages/pymongo-1.9-py2.6-linux-
i686.egg/pymongo/collection.py", line 270, in insert
check_keys, safe, kwargs), safe)
File "/usr/local/lib/python2.6/dist-packages/pymongo-1.9-py2.6-linux-
i686.egg/pymongo/message.py", line 67, in insert
bson_data = "".join([bson.BSON.encode(doc, check_keys) for doc in
docs])
File "/usr/local/lib/python2.6/dist-packages/pymongo-1.9-py2.6-linux-
i686.egg/bson/__init__.py", line 462, in encode
return cls(_dict_to_bson(document, check_keys))
InvalidDocument: key '$date' must not start with '$'


Eliot Horowitz

unread,
Dec 5, 2010, 12:14:58 AM12/5/10
to mongod...@googlegroups.com
Sleepy mongoose doesn't appear to handle the special $date syntax.

You should open a ticket here:
https://github.com/kchodorow/sleepy.mongoose/issues

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

Kristina Chodorow

unread,
Dec 6, 2010, 10:40:37 AM12/6/10
to mongod...@googlegroups.com
Sorry I didn't get back to you on Github.  Just fixed this in master, if you use $date now, it'll insert/query for dates.
Reply all
Reply to author
Forward
0 new messages