-
Notifications
You must be signed in to change notification settings - Fork 107
Home
sleepy.mongoose is a REST interface for MongoDB.
- MongoDB, which can be downloaded from http://www.mongodb.org
- You’ll need to install some Python packages, if you don’t have them already. sleepy.mongoose uses Pymongo, the MongoDB python driver (version 1.4 or greater required). It also requires OpenSSL. You can install these with easy_install:
$ sudo easy_install pymongo pyOpenSSL
Note: sleepy.mongoose only works with Python 2.5 and higher.
Download the latest version.
Start the server by running:
$ python httpd.py
Command line flags:
-
-d
or--docroot
allows you to specify the location of your files. Defaults to the sleepy.mongoose directory
There is a quick tutorial you can use to get started on “my blog.”.http://www.snailinaturtleneck.com/blog/2010/02/22/sleepy-mongoose-a-mongodb-rest-interface/
Sleepy.Mongoose only uses GETs and POSTs right now.
URIs are of the form /db_name/collection_name/_command
Commands are always prefixes by underscores.
To find all documents in the collection “users” in the database “website”, you would use the following:
http://localhost:27080/website/users/_find
You should make sure any options are URL escaped. You can easily do this with any JavaScript shell, including the mongo shell.
To query for {"x" : 1}
, we have the string '{"x" : 1}'
. We run escape('{"x" : 1}')
and get "%7B%22x%22%20%3A%201%7D"
. We can now paste this beautful string into our URL:
http://localhost:27080/website/users/_find?criteria=%7B%22x%22%20%3A%201%7D
{'x' : 1}
is valid JSON, but unfortunately, the Python JSON parser doesn’t think so. You must always use double quotes around keys, e.g., this is valid: {"x" : 1}
.
- Hello, world!
- Connecting
- Inserting
- Removing
- Updating
- Querying
- Getting More Results
- Database Commands
- Honey bunches of helpers: _ensure_index, listing databases, listing collections, dropping things
- Handlers to get $oid, $date, etc. into a proper BSON types
To run the tests, you must install restclient:
$ easy_install restclient
Then run:
$ python t/get.py
$ python t/post.py
If anything goes wrong, please email the MongoDB “user list.”.http://groups.google.com/group/mongodb-user