333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
};