UNPKG

917 BJavaScriptView Raw
1var _defaults = require('lodash.defaults');
2var Readable = require('stream').Readable;
3var inherits = require('util').inherits;
4
5function BaseSampler(db, collectionName, opts) {
6 this.db = db;
7 this.collectionName = collectionName;
8 this.opts = opts;
9
10 opts = _defaults(opts || {}, {
11 query: {},
12 size: 5,
13 fields: null,
14 raw: false,
15 sort: {
16 _id: -1
17 },
18 maxTimeMS: undefined,
19 promoteValues: true
20 });
21
22 this.query = opts.query || {};
23 this.size = opts.size;
24 this.raw = opts.raw;
25 this.fields = opts.fields;
26 this.sort = opts.sort;
27 this.maxTimeMS = opts.maxTimeMS;
28 this.promoteValues = opts.promoteValues;
29
30 Readable.call(this, {
31 objectMode: true
32 });
33}
34inherits(BaseSampler, Readable);
35
36Object.defineProperty(BaseSampler.prototype, 'collection', {
37 get: function() {
38 return this.db.collection(this.collectionName, {});
39 }
40});
41
42module.exports = BaseSampler;