Skip to content

SwellRT meaningful queries

Antonio Tenorio-Fornés edited this page Oct 28, 2016 · 1 revision

SwellRT provides a query service that can be used to obtain useful reports for Teem usage. in this wiki page we will collect them.

Community creators query

A query to obtain a list of users and the communities they have created sorted by the number of communities.

SwellRT.query({
_aggregate:
  [
    {
      $match: {
        $or :
           [{'root.type':'project'},{'root.type':'community'}]
          }
        },
  {
    $unwind: '$participants'
  },
  {
    $group: {_id : '$root.name', 'creator' : {$first: '$participants'}, 'length': {$sum: 1}}
  }, {$group: {_id: '$creator', communities: {$addToSet: '$_id'},  length: {$sum: 1}}},
{$sort: {'length': -1}}

]}, function(r){
      var result = '';
      angular.forEach(r.result, function(r){
        result += r._id + ': ' + r.communities + '\n';
      });
      console.log(result);
    },
    function(e){
      console.log('error', e);
    });

Last Login proxy

A query to obtain the last login of users, (actually, the last time they visited any teem's project)

SwellRT.query({
_aggregate:
  [
    {
      $match: {
        $or :
           [{'root.type':'project'},{'root.type':'community'}]
          }
        },
  {
    $unwind: '$root.lastAccesses'
  },
  {
    $group: {_id : '$root.lastAccesses.user', 'lastVisit' : {$max: '$root.lastAccesses.pad.last'}}
  }, {$sort: {'lastVisit': -1}}
]}, function(r){console.log(r);}, function(e){console.log('error', e);});
Clone this wiki locally