|
2 | 2 |
|
3 | 3 | const Aspect = require('./operation').Aspect;
|
4 | 4 | const defineAspects = require('./operation').defineAspects;
|
5 |
| -const CommandOperation = require('./command'); |
6 |
| -const buildCountCommand = require('./common_functions').buildCountCommand; |
7 |
| -const handleCallback = require('../utils').handleCallback; |
| 5 | +const CommandOperationV2 = require('./command_v2'); |
8 | 6 |
|
9 |
| -class EstimatedDocumentCountOperation extends CommandOperation { |
| 7 | +class EstimatedDocumentCountOperation extends CommandOperationV2 { |
10 | 8 | constructor(collection, options) {
|
11 |
| - super(collection.s.db, options, collection); |
| 9 | + super(collection, options); |
| 10 | + this.collectionName = collection.s.namespace.collection; |
12 | 11 | }
|
13 | 12 |
|
14 |
| - _buildCommand() { |
15 |
| - const coll = this.collection; |
16 |
| - let options = this.options; |
| 13 | + execute(server, callback) { |
| 14 | + const options = this.options; |
| 15 | + const cmd = { count: this.collectionName }; |
| 16 | + if (typeof options.skip === 'number') { |
| 17 | + cmd.skip = options.skip; |
| 18 | + } |
17 | 19 |
|
18 |
| - options.collectionName = coll.collectionName; |
| 20 | + if (typeof options.limit === 'number') { |
| 21 | + cmd.limit = options.limit; |
| 22 | + } |
19 | 23 |
|
20 |
| - return buildCountCommand(coll, null, options); |
21 |
| - } |
| 24 | + if (options.hint) { |
| 25 | + cmd.hint = options.hint; |
| 26 | + } |
| 27 | + |
| 28 | + super.executeCommand(server, cmd, (err, response) => { |
| 29 | + if (err) { |
| 30 | + callback(err); |
| 31 | + return; |
| 32 | + } |
22 | 33 |
|
23 |
| - execute(callback) { |
24 |
| - super.execute((err, result) => { |
25 |
| - if (err) return handleCallback(callback, err); |
26 |
| - handleCallback(callback, null, result.n); |
| 34 | + callback(null, response.n); |
27 | 35 | });
|
28 | 36 | }
|
29 | 37 | }
|
30 | 38 |
|
31 |
| -defineAspects(EstimatedDocumentCountOperation, Aspect.READ_OPERATION); |
| 39 | +defineAspects(EstimatedDocumentCountOperation, [ |
| 40 | + Aspect.READ_OPERATION, |
| 41 | + Aspect.RETRYABLE, |
| 42 | + Aspect.EXECUTE_WITH_SELECTION |
| 43 | +]); |
32 | 44 |
|
33 | 45 | module.exports = EstimatedDocumentCountOperation;
|
0 commit comments