Lenra Docs
Register on Lenra
  • Home
  • Getting started
    Open/Close
  • Guides
    Open/Close
  • Features
    Open/Close
  • References
    Open/Close
  • 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:

    - 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

    OperatorDescription
    $eqMatches values that are equal to a specified value.
    $neMatches all values that are not equal to a specified value.
    $gtMatches all values that are not equal to a specified value.
    $gteMatches values that are greater than or equal to a specified value.
    $ltMatches values that are less than a specified value.
    $lteMatches values that are less than or equal to a specified value.
    $inMatches any of the values specified in an array.
    $ninMatches none of the values specified in an array.

    Logical

    OperatorDescription
    $andJoins query clauses with a logical AND returns all documents that match the conditions of both clauses.
    $orInverts the effect of a query expression and returns documents that do not match the query expression.
    $notJoins query clauses with a logical NOR returns all documents that fail to match both clauses.
    $norJoins query clauses with a logical OR returns all documents that match the conditions of either clause.

    Element

    OperatorDescription
    $existsMatches documents that have the specified field.

    Array

    OperatorDescription
    $allMatches arrays that contain all elements specified in the query.