Data managementContribute
Lenra Data system is based on Mongo. Using our API, you can access and manage this data and utilize the View component to adapt your application interface.
API
To manage the data in your application, you can utilize our REST API. To make a basic API call within Listeners, you can use the "api" object that is passed as the third parameter. This object provides you with the server URL and your authentication token.
CRUD
Create a document, give the content in the body
- POST `${api.url}/app/colls/${coll}/docs`
Read a specific document
- GET `${api.url}/app/colls/${coll}/docs/${id}`
Update a document, give the changes in the body
- PUT `${api.url}/app/colls/${coll}/docs/${doc._id}`
Delete a document
- DELETE `${api.url}/app/colls/${coll}/docs/${doc._id}`
Advanced Mongo functions
find
The MongoDB find function can find many documents in a collection filtered by the query filter.
Run find request, give find params in body like:
- query: the query filter
- projection: the projection map more details here
- POST `${api.url}/app/colls/${coll}/docs/find`
The projection allows you to filter the keys in the return object, by giving a projection map, all keys set to true will be returned, the default values are false, example:
We have in the users collection
{
"_id": "123456",
"name": "John",
"age": 20
}
View
Lenra also allows the use of Mongo find to customize the view's results according to the requested data. Additionally, this behavior automatically updates the interface when a data point corresponding to the view query is changed.
Examples
The next example will call the filteredUsers
view with the user called Thomas
as input data:
{
"type": "view",
"name": "filteredUsers",
"find": {
"coll": "users",
"query": {
"name": "Thomas"
}
}
}
You can get only the names of the users by using this projection:
{
"type": "view",
"name": "userList",
"find": {
"coll": "users",
"projection": {"name": true}
}
}
Limitations
In order to manage realtime refresh of the view we had to implement the Mongo operators in our query-parser project. Since it takes time to implement all the operators (and that we also have lot of work on Lenra) we only have implemented a short list of them. We will implement the rest of them soon, but if you want to help you can look at the list of operator task.
Managed operators
Comparison
Operator | Description |
---|---|
$eq | Matches values that are equal to a specified value. |
$ne | Matches all values that are not equal to a specified value. |
$gt | Matches all values that are not equal to a specified value. |
$gte | Matches values that are greater than or equal to a specified value. |
$lt | Matches values that are less than a specified value. |
$lte | Matches values that are less than or equal to a specified value. |
$in | Matches any of the values specified in an array. |
$nin | Matches none of the values specified in an array. |
Logical
Operator | Description |
---|---|
$and | Joins query clauses with a logical AND returns all documents that match the conditions of both clauses. |
$or | Inverts the effect of a query expression and returns documents that do not match the query expression. |
$not | Joins query clauses with a logical NOR returns all documents that fail to match both clauses. |
$nor | Joins query clauses with a logical OR returns all documents that match the conditions of either clause. |
Element
Operator | Description |
---|---|
$exists | Matches documents that have the specified field. |
Array
Operator | Description |
---|---|
$all | Matches arrays that contain all elements specified in the query. |