Blame view

node_modules/mongojs/test/test-aggregate.js 810 Bytes
46de8790   Tarpit Grover   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var insert = require('./insert');
var concat = require('concat-stream');

insert('aggregate', [{
  name:'Squirtle', type:'water'
}, {
  name:'Starmie' , type:'water'
}, {
  name:'Charmander' , type:'fire'
}, {
  name:'Lapras'  , type:'water'
}], function(db, t, done) {
  db.a.aggregate({$group: {_id: '$type'}}, function(err, types) {
    var arr = types.map(function(x) {return x._id});
    t.equal(types.length, 2);
    t.notEqual(arr.indexOf('fire'), -1);
    t.notEqual(arr.indexOf('water'), -1);

    // test as a stream
    db.a.aggregate({$group: {_id: '$type'}}).pipe(concat(function(types) {
      var arr = types.map(function(x) {return x._id});
      t.equal(types.length, 2);
      t.notEqual(arr.indexOf('fire'), -1);
      t.notEqual(arr.indexOf('water'), -1);
      t.end();
    }));
  });
});