summaryrefslogtreecommitdiffstats
path: root/node_modules/mongodb/lib/operations/count.js
diff options
context:
space:
mode:
authorGravatar Piotr Russ <mail@pruss.it> 2020-11-16 00:10:28 +0100
committerGravatar Piotr Russ <mail@pruss.it> 2020-11-16 00:10:28 +0100
commite06ec920f7a5d784e674c4c4b4e6d1da3dc7391d (patch)
tree55713f725f77b44ebfec86e4eec3ce33e71458ca /node_modules/mongodb/lib/operations/count.js
downloadwebsite_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.tar.gz
website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.tar.bz2
website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.zip
api, login, auth
Diffstat (limited to 'node_modules/mongodb/lib/operations/count.js')
-rw-r--r--node_modules/mongodb/lib/operations/count.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/node_modules/mongodb/lib/operations/count.js b/node_modules/mongodb/lib/operations/count.js
new file mode 100644
index 0000000..a7216d6
--- /dev/null
+++ b/node_modules/mongodb/lib/operations/count.js
@@ -0,0 +1,68 @@
+'use strict';
+
+const buildCountCommand = require('./common_functions').buildCountCommand;
+const OperationBase = require('./operation').OperationBase;
+
+class CountOperation extends OperationBase {
+ constructor(cursor, applySkipLimit, options) {
+ super(options);
+
+ this.cursor = cursor;
+ this.applySkipLimit = applySkipLimit;
+ }
+
+ execute(callback) {
+ const cursor = this.cursor;
+ const applySkipLimit = this.applySkipLimit;
+ const options = this.options;
+
+ if (applySkipLimit) {
+ if (typeof cursor.cursorSkip() === 'number') options.skip = cursor.cursorSkip();
+ if (typeof cursor.cursorLimit() === 'number') options.limit = cursor.cursorLimit();
+ }
+
+ // Ensure we have the right read preference inheritance
+ if (options.readPreference) {
+ cursor.setReadPreference(options.readPreference);
+ }
+
+ if (
+ typeof options.maxTimeMS !== 'number' &&
+ cursor.cmd &&
+ typeof cursor.cmd.maxTimeMS === 'number'
+ ) {
+ options.maxTimeMS = cursor.cmd.maxTimeMS;
+ }
+
+ let finalOptions = {};
+ finalOptions.skip = options.skip;
+ finalOptions.limit = options.limit;
+ finalOptions.hint = options.hint;
+ finalOptions.maxTimeMS = options.maxTimeMS;
+
+ // Command
+ finalOptions.collectionName = cursor.namespace.collection;
+
+ let command;
+ try {
+ command = buildCountCommand(cursor, cursor.cmd.query, finalOptions);
+ } catch (err) {
+ return callback(err);
+ }
+
+ // Set cursor server to the same as the topology
+ cursor.server = cursor.topology.s.coreTopology;
+
+ // Execute the command
+ cursor.topology.command(
+ cursor.namespace.withCollection('$cmd'),
+ command,
+ cursor.options,
+ (err, result) => {
+ callback(err, result ? result.result.n : null);
+ }
+ );
+ }
+}
+
+module.exports = CountOperation;