summaryrefslogtreecommitdiffstats
path: root/node_modules/mongodb/lib/operations/drop.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/mongodb/lib/operations/drop.js')
-rw-r--r--node_modules/mongodb/lib/operations/drop.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/node_modules/mongodb/lib/operations/drop.js b/node_modules/mongodb/lib/operations/drop.js
new file mode 100644
index 0000000..be03716
--- /dev/null
+++ b/node_modules/mongodb/lib/operations/drop.js
@@ -0,0 +1,53 @@
+'use strict';
+
+const Aspect = require('./operation').Aspect;
+const CommandOperation = require('./command');
+const defineAspects = require('./operation').defineAspects;
+const handleCallback = require('../utils').handleCallback;
+
+class DropOperation extends CommandOperation {
+ constructor(db, options) {
+ const finalOptions = Object.assign({}, options, db.s.options);
+
+ if (options.session) {
+ finalOptions.session = options.session;
+ }
+
+ super(db, finalOptions);
+ }
+
+ execute(callback) {
+ super.execute((err, result) => {
+ if (err) return handleCallback(callback, err);
+ if (result.ok) return handleCallback(callback, null, true);
+ handleCallback(callback, null, false);
+ });
+ }
+}
+
+defineAspects(DropOperation, Aspect.WRITE_OPERATION);
+
+class DropCollectionOperation extends DropOperation {
+ constructor(db, name, options) {
+ super(db, options);
+
+ this.name = name;
+ this.namespace = `${db.namespace}.${name}`;
+ }
+
+ _buildCommand() {
+ return { drop: this.name };
+ }
+}
+
+class DropDatabaseOperation extends DropOperation {
+ _buildCommand() {
+ return { dropDatabase: 1 };
+ }
+}
+
+module.exports = {
+ DropOperation,
+ DropCollectionOperation,
+ DropDatabaseOperation
+};