Sha256: ff14c9e97c82da45a8534b45369c8fecd1571aeb5d6bad08fd595e7e2a076da5

Contents?: true

Size: 679 Bytes

Versions: 12

Compression:

Stored size: 679 Bytes

Contents

function find_tags(collection, regex, query, limit) {
  var counts = db.eval(
    function(collection, regex, query){
      var counts = {};
      db[collection].find(query, {"tags":1}).limit(500).forEach(
        function(p){
          if ( p.tags ){
            for ( var i=0; i<p.tags.length; i++ ){
              var name = p.tags[i];
              if(name.match(regex) != null)
                counts[name] = 1 + ( counts[name] || 0 );
            }
          }
        }
      );
      return counts;
    },
    collection,
    regex,
    query
  );

  var tags = [];
  for ( var tag in counts ){
    tags.push( { name : tag , count : counts[tag] } )
  }

  return tags;
}

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
mongoid_ext-0.9.0 lib/mongoid_ext/js/find_tags.js
mongoid_ext-0.7.1 lib/mongoid_ext/js/find_tags.js
mongomapper_ext-0.5.2 lib/mongomapper_ext/js/find_tags.js
mongomapper_ext-0.5.1 lib/mongomapper_ext/js/find_tags.js
mongomapper_ext-0.5.0 lib/mongomapper_ext/js/find_tags.js
mongomapper_ext-0.4.0 lib/mongomapper_ext/js/find_tags.js
mongomapper_ext-0.3.0 lib/mongomapper_ext/js/find_tags.js
mongomapper_ext-0.2.4 lib/mongomapper_ext/js/find_tags.js
mongomapper_ext-0.2.3 lib/mongomapper_ext/js/find_tags.js
mongomapper_ext-0.2.2 lib/mongomapper_ext/js/find_tags.js
mongomapper_ext-0.2.1 lib/mongomapper_ext/js/find_tags.js
mongomapper_ext-0.2.0 lib/mongomapper_ext/js/find_tags.js