POST datastore/schemas/:schema name/objects/search
From Social ID Developers
(Difference between revisions)
Renato.neves (Talk | contribs) |
(→Description) |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 3: | Line 3: | ||
Searches for Objects in the Schema. | Searches for Objects in the Schema. | ||
− | The datastore schema search is powered by a limited version of the [ | + | The datastore schema search is powered by a limited version of the [https://docs.mongodb.com/v3.4/reference/operator/aggregation-pipeline/ MongoDB Aggregation Pipeline]. |
Some operators and stages are not allowed in the datastore searches. The set of allowed operators is: | Some operators and stages are not allowed in the datastore searches. The set of allowed operators is: | ||
Line 13: | Line 13: | ||
* Group accumulator operators: $sum $avg $first $last $max $min $push $addToSet | * Group accumulator operators: $sum $avg $first $last $max $min $push $addToSet | ||
* Date operators: $dayOfYear $dayOfMonth $dayOfWeek $year $month $week $hour $minute $second $millisecond | * Date operators: $dayOfYear $dayOfMonth $dayOfWeek $year $month $week $hour $minute $second $millisecond | ||
− | * String operators: $concat $substr $toLower $toUpper $strcasecmp $regex | + | * String operators: $concat $substr $toLower $toUpper $strcasecmp $regex $options |
* Arithmetic operators: $add $subtract $multiply $divide $mod | * Arithmetic operators: $add $subtract $multiply $divide $mod | ||
* Set operators: $setEquals $setIntersection $setUnion $setDifference $setIsSubset $anyElementTrue $allElementsTrue | * Set operators: $setEquals $setIntersection $setUnion $setDifference $setIsSubset $anyElementTrue $allElementsTrue | ||
+ | |||
+ | And the available stages are: | ||
+ | |||
+ | * match | ||
+ | * group | ||
+ | * project | ||
+ | * sort | ||
+ | * limit | ||
+ | * skip | ||
+ | |||
+ | You can find examples in the [https://docs.mongodb.com/v3.4/reference/operator/aggregation-pipeline/ MongoDB documentation], including a [https://docs.mongodb.com/v3.4/reference/sql-aggregation-comparison/ SQL to Aggregation Map]. The JSON parameters for each stage follows the same structure from MongoDB examples. Example: | ||
+ | |||
+ | MongoDB for the SQL "SELECT COUNT(*) AS count FROM orders": | ||
+ | |||
+ | db.orders.aggregate( [ | ||
+ | { | ||
+ | $group: { | ||
+ | _id: null, | ||
+ | count: { $sum: 1 } | ||
+ | } | ||
+ | } | ||
+ | ] ) | ||
+ | |||
+ | JSON Parameters: | ||
+ | |||
+ | { | ||
+ | "stages": [ | ||
+ | { | ||
+ | "group": { | ||
+ | "_id": null, | ||
+ | "count": { "$sum": 1 } | ||
+ | } | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | |||
+ | or: | ||
+ | |||
+ | { | ||
+ | "group": { | ||
+ | "_id": null, | ||
+ | "count": { "$sum": 1 } | ||
+ | } | ||
+ | } | ||
== Resource URL == | == Resource URL == | ||
Line 36: | Line 80: | ||
! align="left" width="200px" | stages | ! align="left" width="200px" | stages | ||
| width="200px" | optional | | width="200px" | optional | ||
− | | | + | | an array of hashes in the format stage:value |
|- | |- | ||
! align="left" width="200px" | match | ! align="left" width="200px" | match | ||
Line 65: | Line 109: | ||
== Authentication == | == Authentication == | ||
− | This API requires | + | This API requires Account authentication. See [[Authentication]]. |
== Response == | == Response == |
Latest revision as of 17:16, 23 April 2020
Contents |
Description
Searches for Objects in the Schema.
The datastore schema search is powered by a limited version of the MongoDB Aggregation Pipeline.
Some operators and stages are not allowed in the datastore searches. The set of allowed operators is:
- Comparison operators: $gt $gte $lt $lte $ne $in $nin
- Boolean operators: $or $and $not $nor
- Element operators: $exists
- Array operators: $all $elemMatch $size
- Group accumulator operators: $sum $avg $first $last $max $min $push $addToSet
- Date operators: $dayOfYear $dayOfMonth $dayOfWeek $year $month $week $hour $minute $second $millisecond
- String operators: $concat $substr $toLower $toUpper $strcasecmp $regex $options
- Arithmetic operators: $add $subtract $multiply $divide $mod
- Set operators: $setEquals $setIntersection $setUnion $setDifference $setIsSubset $anyElementTrue $allElementsTrue
And the available stages are:
- match
- group
- project
- sort
- limit
- skip
You can find examples in the MongoDB documentation, including a SQL to Aggregation Map. The JSON parameters for each stage follows the same structure from MongoDB examples. Example:
MongoDB for the SQL "SELECT COUNT(*) AS count FROM orders":
db.orders.aggregate( [ { $group: { _id: null, count: { $sum: 1 } } } ] )
JSON Parameters:
{ "stages": [ { "group": { "_id": null, "count": { "$sum": 1 } } } ] }
or:
{ "group": { "_id": null, "count": { "$sum": 1 } } }
Resource URL
POST https://api.socialidnow.com/v1/marketing/datastore/schemas/:schema_name/objects/search
Parameters
URL Parameters
schema_name | required | schema name. |
---|
JSON Parameters
stages | optional | an array of hashes in the format stage:value |
---|---|---|
match | optional | a match stage |
group | optional | a group stage |
sort | optional | a sort stage |
project | optional | a project stage |
skip | optional | a skip stage |
limit | optional | a limit stage |
Authentication
This API requires Account authentication. See Authentication.
Response
Response Status
ok (200) | The search was performed successfully. |
---|---|
unauthorized (401) | The authentication is wrong. See Authentication. |
not_found (404) | The schema was not found. |
internal_server_error (500) | An unknown error happened. |
Response Body
A successful search returns the following fields:
total | total amount of objects found. |
---|---|
count | amount of objects returned in this page. |
offset | amount of discarded objects (page start). |
results | array with object details. |
Examples
Request
Returns all objects from the schema named "my_schema" which have the attribute "email" present:
curl -iX POST 'https://api.socialidnow.com/v1/marketing/datastore/schemas/my_schema/objects/search' \ -d "{\"match\":{\"email\":{\"\$exists\":true}}}" \ -H 'Content-type: application/json' \ --user 138:e8b9ca24f1b590af67e6271297d6e1f7226625d61c5b5daa1b2f215464e292cf
Response
Response Headers
HTTP/1.1 200 Ok Status: 200
Response Body
{ "total": 2, "count": 2, "offset": 0, "results": [ { "object_id": "54481188e5cb7cffe4000003", "user_id": 340, "created_at": "2014-10-24T14:48:00Z", "updated_at": "2014-10-24T14:48:00Z", "email": "john@example.com", "second_field": 123 }, { ... } ] }