UNPKG

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