index.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. 'use strict';
  2. // Core module
  3. const core = require('./lib/core');
  4. const Instrumentation = require('./lib/apm');
  5. // Set up the connect function
  6. const connect = require('./lib/mongo_client').connect;
  7. // Expose error class
  8. connect.MongoError = core.MongoError;
  9. connect.MongoNetworkError = core.MongoNetworkError;
  10. connect.MongoTimeoutError = core.MongoTimeoutError;
  11. connect.MongoServerSelectionError = core.MongoServerSelectionError;
  12. connect.MongoParseError = core.MongoParseError;
  13. connect.MongoWriteConcernError = core.MongoWriteConcernError;
  14. connect.MongoBulkWriteError = require('./lib/bulk/common').BulkWriteError;
  15. connect.BulkWriteError = connect.MongoBulkWriteError;
  16. // Expose server versions
  17. connect.ServerApiVersion = core.ServerApiVersion;
  18. // Actual driver classes exported
  19. connect.Admin = require('./lib/admin');
  20. connect.MongoClient = require('./lib/mongo_client');
  21. connect.Db = require('./lib/db');
  22. connect.Collection = require('./lib/collection');
  23. connect.Server = require('./lib/topologies/server');
  24. connect.ReplSet = require('./lib/topologies/replset');
  25. connect.Mongos = require('./lib/topologies/mongos');
  26. connect.ReadPreference = core.ReadPreference;
  27. connect.GridStore = require('./lib/gridfs/grid_store');
  28. connect.Chunk = require('./lib/gridfs/chunk');
  29. connect.Logger = core.Logger;
  30. connect.AggregationCursor = require('./lib/aggregation_cursor');
  31. connect.CommandCursor = require('./lib/command_cursor');
  32. connect.Cursor = require('./lib/cursor');
  33. connect.GridFSBucket = require('./lib/gridfs-stream');
  34. // Exported to be used in tests not to be used anywhere else
  35. connect.CoreServer = core.Server;
  36. connect.CoreConnection = core.Connection;
  37. // BSON types exported
  38. connect.Binary = core.BSON.Binary;
  39. connect.Code = core.BSON.Code;
  40. connect.Map = core.BSON.Map;
  41. connect.DBRef = core.BSON.DBRef;
  42. connect.Double = core.BSON.Double;
  43. connect.Int32 = core.BSON.Int32;
  44. connect.Long = core.BSON.Long;
  45. connect.MinKey = core.BSON.MinKey;
  46. connect.MaxKey = core.BSON.MaxKey;
  47. /** @deprecated Please use `ObjectId` */
  48. connect.ObjectID = core.BSON.ObjectID;
  49. connect.ObjectId = core.BSON.ObjectID;
  50. connect.Symbol = core.BSON.Symbol;
  51. connect.Timestamp = core.BSON.Timestamp;
  52. connect.BSONRegExp = core.BSON.BSONRegExp;
  53. connect.Decimal128 = core.BSON.Decimal128;
  54. // Add connect method
  55. connect.connect = connect;
  56. // Set up the instrumentation method
  57. connect.instrument = function(options, callback) {
  58. if (typeof options === 'function') {
  59. callback = options;
  60. options = {};
  61. }
  62. const instrumentation = new Instrumentation();
  63. instrumentation.instrument(connect.MongoClient, callback);
  64. return instrumentation;
  65. };
  66. // Set our exports to be the connect function
  67. module.exports = connect;