1 | var _defaults = require('lodash.defaults');
|
2 | var Readable = require('stream').Readable;
|
3 | var inherits = require('util').inherits;
|
4 |
|
5 | function 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 | }
|
34 | inherits(BaseSampler, Readable);
|
35 |
|
36 | Object.defineProperty(BaseSampler.prototype, 'collection', {
|
37 | get: function() {
|
38 | return this.db.collection(this.collectionName, {});
|
39 | }
|
40 | });
|
41 |
|
42 | module.exports = BaseSampler;
|