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 '$'