create_collection.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.CreateCollectionOperation = void 0;
  4. const collection_1 = require("../collection");
  5. const command_1 = require("./command");
  6. const operation_1 = require("./operation");
  7. const ILLEGAL_COMMAND_FIELDS = new Set([
  8. 'w',
  9. 'wtimeout',
  10. 'j',
  11. 'fsync',
  12. 'autoIndexId',
  13. 'pkFactory',
  14. 'raw',
  15. 'readPreference',
  16. 'session',
  17. 'readConcern',
  18. 'writeConcern',
  19. 'raw',
  20. 'fieldsAsRaw',
  21. 'promoteLongs',
  22. 'promoteValues',
  23. 'promoteBuffers',
  24. 'bsonRegExp',
  25. 'serializeFunctions',
  26. 'ignoreUndefined',
  27. 'enableUtf8Validation'
  28. ]);
  29. /** @internal */
  30. class CreateCollectionOperation extends command_1.CommandOperation {
  31. constructor(db, name, options = {}) {
  32. super(db, options);
  33. this.options = options;
  34. this.db = db;
  35. this.name = name;
  36. }
  37. execute(server, session, callback) {
  38. const db = this.db;
  39. const name = this.name;
  40. const options = this.options;
  41. const done = err => {
  42. if (err) {
  43. return callback(err);
  44. }
  45. callback(undefined, new collection_1.Collection(db, name, options));
  46. };
  47. const cmd = { create: name };
  48. for (const n in options) {
  49. if (options[n] != null &&
  50. typeof options[n] !== 'function' &&
  51. !ILLEGAL_COMMAND_FIELDS.has(n)) {
  52. cmd[n] = options[n];
  53. }
  54. }
  55. // otherwise just execute the command
  56. super.executeCommand(server, session, cmd, done);
  57. }
  58. }
  59. exports.CreateCollectionOperation = CreateCollectionOperation;
  60. (0, operation_1.defineAspects)(CreateCollectionOperation, [operation_1.Aspect.WRITE_OPERATION]);
  61. //# sourceMappingURL=create_collection.js.map