// --------------------------------------------------------------------------------------
// TODO
// --------------------------------------------------------------------------------------
exp.check_filter = function(query, fields)
{
  var ret = {};

  for(var field in fields) {
    if(query[fields[field]]) {
      ret[fields[field]] = query[fields[field]];    // add to result
      delete query[fields[field]];                  // delete original item
    }
  }

  return ret;
}
// --------------------------------------------------------------------------------------
// add other operators, if defined in query
// --------------------------------------------------------------------------------------
exp.add_ops = function(aggregate_query, query)
{
  if(query.sort) {
    aggregate_query.push({ $sort : query.sort });   // sort
  }

  if(query.skip && query.limit) {   // both skip and limit
    aggregate_query.push({ $limit : query.limit + query.skip });   // limit to limit + skip
  }

  if(query.skip) {
    aggregate_query.push({ $skip : query.skip });   // skip
  }

  if(query.limit) {
    aggregate_query.push({ $limit : query.limit }); // limit
  }

  return aggregate_query;
}
// --------------------------------------------------------------------------------------
// TODO
// --------------------------------------------------------------------------------------
exp.add_cond = function(aggregate_query, cond)
{
  //console.log("before");
  //console.log(aggregate_query);

  if(Object.keys(cond).length > 0)
    aggregate_query.push({ $match : cond });    // check


  //console.log("after");
  //console.log(aggregate_query);

  return aggregate_query;
}
// --------------------------------------------------------------------------------------
module.exports = exp;

@@ -78,36 +78,139 @@
 ------------%0A// 
-TODO
+check if any of fileds is present in query%0A// if so, delete it and return as dict for%0A// further processing
 %0A// ------------
@@ -1386,12 +1386,58 @@
 %0A// 
-TODO
+add initial removed condition to aggregation query
 %0A// 
@@ -1576,70 +1576,8 @@
 )%0A%7B%0A
-  //console.log(%22before%22);%0A  //console.log(aggregate_query);%0A%0A
   if
@@ -1669,70 +1669,8 @@
 ck%0A%0A
-%0A  //console.log(%22after%22);%0A  //console.log(aggregate_query);%0A%0A
   re

update code