Skip to content
This repository has been archived by the owner on Jan 8, 2019. It is now read-only.

[API] GET

padewitte edited this page Nov 7, 2014 · 1 revision

GET rest/{database}/{collection}/

List all items contains in the collection in url.

The request will return all items in JSON Format. You can filter by setting the parameter query with a valid MongoDB query. You can only count items by settings the parameter count with value true. You can get col stats by settings colstatsparameter with value true. You can perform a aggregate operation on collection by setting aggregate parametre with a valid pipeline.

You may set the content-type to application-json.

If your url is too long you could use header parameter instead of query parameter. It is totaly equivalent.

Request parameters

Parameter Type Mandatory Comment

{database}

url

yes

database name

{collection}

url

yes

collection name

query

url or header

no

Contains a matching query to filter the result of a find. This header should contains a valid criteria

sortby

url or header

no

Sort items with the JSON filter object in header. See MongoDB sort operation and examples. Should be use with indexed fields.

numToSkip

url or header

no

Integer. Discards a given number of elements at the beginning of the cursor.

batchSize

url or header

no

Integer. TODO

fieldsFilter

url or header

no

Perform a projection as describe in MongoDB documentation. Usefull when to discard or only show some fileds of a document.

count

url or header

no

Perform a count of items in collection or matching the query. Could no be used with aggregate.

colstats

url or header

no

Perform a getColStats instead of a find on collection specifie in url. The headers querie, count and aggregate could not be used at the same time.

colstats

url or header

no

Perform a aggregate on collection. This header should contain a valid aggregate pipeline. The Headers querie, count and getColStats could not be used at the same time.

Result

Parameter Type Mandatory Comment

body

body

yes

Array of JSON Object.

A 204 HTTP response code is send if collection does not exist or if no document where found

Examples

To get all items in collection test with name matching Sylvain CHAVANEL.

curl -X GET -H "query:{'name' : 'Sylvain CHAVANEL'}" http://127.0.0.1:8667/kupra/test/col`

[
  {
    _id : "1" ,
    name : "Sylvain CHAVANEL"
  }
]`
To count all items in collection test
2
To obtain coll stats of collection test

curl -X GET -H "getColStats:true" http://127.0.0.1:8667/kupra/test/col

{
  "serverUsed" : "/127.0.0.1:27017" ,
  "ns" : "mrc.test" ,
  "count" : 2 ,
  "size" : 88 ,
  "avgObjSize" : 44.0 ,
  "storageSize" : 4096 ,
  "numExtents" : 1 ,
  "nindexes" : 1 ,
  "lastExtentSize" : 4096 ,
  "paddingFactor" : 1.0 ,
  "systemFlags" : 1 ,
  "userFlags" : 0 ,
  "totalIndexSize" : 8176 ,
  "indexSizes" : { "_id_" : 8176} ,
  "ok" : 1.0
}
To perform an aggregation operation

To run this example just load data as explain here

curl -X GET -H "aggregate:{ $group : { _id : '$state', totalPop : { $sum : '$pop' } } }, { $match : {city : 'EVANSTON' , totalPop : { $gte : 10*1000*1000 } } }" http://127.0.0.1:8667/mrc/zipcode

2
To get all items with all fields except _id
To sort items by their id desc
To limit the number of items returned

curl -i -X GET http://127.0.0.1:8667/kupra/test/zipcode?query={'city' : 'KEYSTONE'}&limit=1

HTTP/1.1 200 OK
...
ResultTotalSize: 6
ResultPageSize: 6
...
[
  {
    "city" : "KEYSTONE" ,
    "loc" : [ -86.812861 , 33.236868] ,
    "pop" : 14218 ,
    "state" : "AL" ,
    "_id" : "35007"
  }
]