Skip to content
Pablo Ojanguren edited this page Mar 20, 2017 · 1 revision

Users can query the server to look up collaborative objects following some conditions. Use the SwellRT.query(query, onSuccess, onFailure) method. Users only have access -and can retrieve- those objects in which they are participating. The query parameter can be both a string or a JavaScript object standing for a MondoDB query expression.


// Get all objects for the logged in user

SwellRT.query("{}",

              function(response) {

                // response.result is the array of data modeles

              },

              function(error) {

                // handle the error

              });

Objects are represented as JSON objects:

{"result":[

 { "wave_id" : "local.net/s+SW-JnsVO14A" ,
   "participants" : [ "[email protected]" , "[email protected]"] ,
   "root" : {
        "list" : [ "String one" , "String two"]
            }
 },

 { "wave_id" : "local.net/s+Nfz-Pxo0e8A" ,
   "participants" : [ "[email protected]"] ,
   "root" : {
        "list" : [ "Hello World" , "This" , "is an" , "array"]
            }
  }

MongoDB Projections

To use a MongoDB projection in the query, simply call SwellRT.query method with an object with the following structure as the query param:

SwellRT.query(
  { _query : <the query object>,
    _projection: <the projection object>
  }, function ...);

MongoDB Aggregates

To use MongoDB aggregates, use an object with the aggregate expression in the _aggregate field as query parameter of the SwellRT.query method :

SwellRT.query(
  { _aggregate: [
       <aggregation stages expressions>
    ]
  }, function ...);