Created
June 9, 2012 13:07
-
-
Save jasonrudolph/2900920 to your computer and use it in GitHub Desktop.
Passing Query and Sort Params to MongoHQ RESTful API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assuming you're familiar with specifying query and sort options | |
# via the MongoDB console as shown here, you can specify these same | |
# options via the MongoHQ RESTful API using the approach shown in the | |
# file below. | |
$ mongo staff.mongohq.com:10095/one-rep-max -u REDACTED -p | |
MongoDB shell version: 2.0.4 | |
Enter password: | |
connecting to: staff.mongohq.com:10095/one-rep-max | |
> use one-rep-max; | |
switched to db one-rep-max | |
> db.sets.find({"exercise-id" : "4f511918c7e7c70001003a67"}).sort({"_id": -1}).limit(5); | |
{ "_id" : ObjectId("4fd338f8485c690001000006"), "reps" : "5", "exercise-id" : "4f511918c7e7c70001003a67", "weight" : "205" } | |
{ "_id" : ObjectId("4fd338f409fa7f0001000005"), "reps" : "5", "exercise-id" : "4f511918c7e7c70001003a67", "weight" : "195" } | |
{ "_id" : ObjectId("4fd338ee485c690001000005"), "reps" : "5", "exercise-id" : "4f511918c7e7c70001003a67", "weight" : "185" } | |
{ "_id" : ObjectId("4fc913425135fb0001000005"), "exercise-id" : "4f511918c7e7c70001003a67", "reps" : "5", "weight" : "155" } | |
{ "_id" : ObjectId("4fc9133e030be90001000003"), "exercise-id" : "4f511918c7e7c70001003a67", "reps" : "5", "weight" : "135" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Docs: http://support.mongohq.com/api/documents/index.html | |
# | |
# To include query and sort options when fetching documents, specify the | |
# parameters ("q" and "sort" respectively) as URI-encoded JSON documents. | |
# For example... | |
# | |
# === Query Options === | |
# | |
# To use the same query options shown in the Mongo console above: | |
# | |
# {"exercise-id" : "4f511918c7e7c70001003a67"} | |
# | |
# URI encode this JSON document: | |
# | |
# %7B%22exercise-id%22:%224f511918c7e7c70001003a67%22%7D | |
# | |
# Then, use this as the value of the "q" parameter. | |
# | |
# === Sort Options === | |
# | |
# To use the same sort options shown in the Mongo console above: | |
# | |
# {"_id": -1} | |
# | |
# URI encode this JSON document: | |
# | |
# %7B%22_id%22:-1%7D | |
# | |
# Then, use this as the value of the "sort" parameter. | |
$ curl -X GET "https://api.mongohq.com/databases/one-rep-max/collections/sets/documents?_apikey=REDACTED&limit=5&q=%7B%22exercise-id%22:%224f511918c7e7c70001003a67%22%7D&sort=%7B%22_id%22:-1%7D" | |
[ | |
{"_id":{"$oid": "4fd338f8485c690001000006"},"reps":"5","exercise-id":"4f511918c7e7c70001003a67","weight":"205"}, | |
{"_id":{"$oid": "4fd338f409fa7f0001000005"},"reps":"5","exercise-id":"4f511918c7e7c70001003a67","weight":"195"}, | |
{"_id":{"$oid": "4fd338ee485c690001000005"},"reps":"5","exercise-id":"4f511918c7e7c70001003a67","weight":"185"}, | |
{"_id":{"$oid": "4fc913425135fb0001000005"},"exercise-id":"4f511918c7e7c70001003a67","reps":"5","weight":"155"}, | |
{"_id":{"$oid": "4fc9133e030be90001000003"},"exercise-id":"4f511918c7e7c70001003a67","reps":"5","weight":"135"} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For more info, see the MongoHQ RESTful API documentation.