index.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. // Actual driver classes exported
  17. connect.Admin = require('./lib/admin');
  18. connect.MongoClient = require('./lib/mongo_client');
  19. connect.Db = require('./lib/db');
  20. connect.Collection = require('./lib/collection');
  21. connect.Server = require('./lib/topologies/server');
  22. connect.ReplSet = require('./lib/topologies/replset');
  23. connect.Mongos = require('./lib/topologies/mongos');
  24. connect.ReadPreference = core.ReadPreference;
  25. connect.GridStore = require('./lib/gridfs/grid_store');
  26. connect.Chunk = require('./lib/gridfs/chunk');
  27. connect.Logger = core.Logger;
  28. connect.AggregationCursor = require('./lib/aggregation_cursor');
  29. connect.CommandCursor = require('./lib/command_cursor');
  30. connect.Cursor = require('./lib/cursor');
  31. connect.GridFSBucket = require('./lib/gridfs-stream');
  32. // Exported to be used in tests not to be used anywhere else
  33. connect.CoreServer = core.Server;
  34. connect.CoreConnection = core.Connection;
  35. // BSON types exported
  36. connect.Binary = core.BSON.Binary;
  37. connect.Code = core.BSON.Code;
  38. connect.Map = core.BSON.Map;
  39. connect.DBRef = core.BSON.DBRef;
  40. connect.Double = core.BSON.Double;
  41. connect.Int32 = core.BSON.Int32;
  42. connect.Long = core.BSON.Long;
  43. connect.MinKey = core.BSON.MinKey;
  44. connect.MaxKey = core.BSON.MaxKey;
  45. connect.ObjectID = core.BSON.ObjectID;
  46. connect.ObjectId = core.BSON.ObjectID;
  47. connect.Symbol = core.BSON.Symbol;
  48. connect.Timestamp = core.BSON.Timestamp;
  49. connect.BSONRegExp = core.BSON.BSONRegExp;
  50. connect.Decimal128 = core.BSON.Decimal128;
  51. // Add connect method
  52. connect.connect = connect;
  53. // Set up the instrumentation method
  54. connect.instrument = function(options, callback) {
  55. if (typeof options === 'function') {
  56. callback = options;
  57. options = {};
  58. }
  59. const instrumentation = new Instrumentation();
  60. instrumentation.instrument(connect.MongoClient, callback);
  61. return instrumentation;
  62. };
  63. // Set our exports to be the connect function
  64. module.exports = connect;