1
1
'use strict' ;
2
2
3
- const EventEmitter = require ( 'events' ) ;
4
- const { inherits, deprecate } = require ( 'util' ) ;
3
+ const { deprecate } = require ( 'util' ) ;
5
4
const { AggregationCursor, CommandCursor } = require ( './cursor' ) ;
6
5
const { ObjectID } = require ( './utils' ) . retrieveBSON ( ) ;
7
6
const ReadPreference = require ( './read_preference' ) ;
@@ -26,7 +25,6 @@ const {
26
25
27
26
// Operations
28
27
const {
29
- createListener,
30
28
ensureIndex,
31
29
evaluate,
32
30
profilingInfo,
@@ -88,7 +86,6 @@ const legalOptionNames = [
88
86
'readConcern' ,
89
87
'retryMiliSeconds' ,
90
88
'numberOfRetries' ,
91
- 'parentDb' ,
92
89
'noListener' ,
93
90
'loggerLevel' ,
94
91
'logger' ,
@@ -130,18 +127,11 @@ const legalOptionNames = [
130
127
* @property {boolean } slaveOk The current slaveOk value for the db instance.
131
128
* @property {object } writeConcern The current write concern values.
132
129
* @property {object } topology Access the topology object (single server, replicaset or mongos).
133
- * @fires Db#close
134
- * @fires Db#reconnect
135
- * @fires Db#error
136
- * @fires Db#timeout
137
- * @fires Db#parseError
138
- * @fires Db#fullsetup
139
130
* @return {Db } a Db instance.
140
131
*/
141
132
function Db ( databaseName , topology , options ) {
142
133
options = options || { } ;
143
134
if ( ! ( this instanceof Db ) ) return new Db ( databaseName , topology , options ) ;
144
- EventEmitter . call ( this ) ;
145
135
146
136
// Get the promiseLibrary
147
137
const promiseLibrary = options . promiseLibrary || Promise ;
@@ -156,8 +146,6 @@ function Db(databaseName, topology, options) {
156
146
this . s = {
157
147
// DbCache
158
148
dbCache : { } ,
159
- // Children db's
160
- children : [ ] ,
161
149
// Topology
162
150
topology : topology ,
163
151
// Options
@@ -170,8 +158,6 @@ function Db(databaseName, topology, options) {
170
158
readPreference : ReadPreference . fromOptions ( options ) ,
171
159
// Set buffermaxEntries
172
160
bufferMaxEntries : typeof options . bufferMaxEntries === 'number' ? options . bufferMaxEntries : - 1 ,
173
- // Parent db (if chained)
174
- parentDb : options . parentDb || null ,
175
161
// Set up the primary key factory or fallback to ObjectID
176
162
pkFactory : options . pkFactory || ObjectID ,
177
163
// Get native parser
@@ -195,23 +181,9 @@ function Db(databaseName, topology, options) {
195
181
getSingleProperty ( this , 'bufferMaxEntries' , this . s . bufferMaxEntries ) ;
196
182
getSingleProperty ( this , 'databaseName' , this . s . namespace . db ) ;
197
183
198
- // This is a child db, do not register any listeners
199
- if ( options . parentDb ) return ;
200
184
if ( this . s . noListener ) return ;
201
-
202
- // Add listeners
203
- topology . on ( 'error' , createListener ( this , 'error' , this ) ) ;
204
- topology . on ( 'timeout' , createListener ( this , 'timeout' , this ) ) ;
205
- topology . on ( 'close' , createListener ( this , 'close' , this ) ) ;
206
- topology . on ( 'parseError' , createListener ( this , 'parseError' , this ) ) ;
207
- topology . once ( 'open' , createListener ( this , 'open' , this ) ) ;
208
- topology . once ( 'fullsetup' , createListener ( this , 'fullsetup' , this ) ) ;
209
- topology . once ( 'all' , createListener ( this , 'all' , this ) ) ;
210
- topology . on ( 'reconnect' , createListener ( this , 'reconnect' , this ) ) ;
211
185
}
212
186
213
- inherits ( Db , EventEmitter ) ;
214
-
215
187
// Topology
216
188
Object . defineProperty ( Db . prototype , 'topology' , {
217
189
enumerable : true ,
@@ -789,11 +761,6 @@ Db.prototype.ensureIndex = deprecate(function(name, fieldOrSpec, options, callba
789
761
] ) ;
790
762
} , 'Db.ensureIndex is deprecated as of MongoDB version 3.0 / driver version 2.0' ) ;
791
763
792
- Db . prototype . addChild = function ( db ) {
793
- if ( this . s . parentDb ) return this . s . parentDb . addChild ( db ) ;
794
- this . s . children . push ( db ) ;
795
- } ;
796
-
797
764
/**
798
765
* Add a user to the database.
799
766
* @method
@@ -963,64 +930,6 @@ Db.prototype.getLogger = function() {
963
930
return this . s . logger ;
964
931
} ;
965
932
966
- /**
967
- * Db close event
968
- *
969
- * Emitted after a socket closed against a single server or mongos proxy.
970
- *
971
- * @event Db#close
972
- * @type {MongoError }
973
- */
974
-
975
- /**
976
- * Db reconnect event
977
- *
978
- * * Server: Emitted when the driver has reconnected and re-authenticated.
979
- * * ReplicaSet: N/A
980
- * * Mongos: Emitted when the driver reconnects and re-authenticates successfully against a Mongos.
981
- *
982
- * @event Db#reconnect
983
- * @type {object }
984
- */
985
-
986
- /**
987
- * Db error event
988
- *
989
- * Emitted after an error occurred against a single server or mongos proxy.
990
- *
991
- * @event Db#error
992
- * @type {MongoError }
993
- */
994
-
995
- /**
996
- * Db timeout event
997
- *
998
- * Emitted after a socket timeout occurred against a single server or mongos proxy.
999
- *
1000
- * @event Db#timeout
1001
- * @type {MongoError }
1002
- */
1003
-
1004
- /**
1005
- * Db parseError event
1006
- *
1007
- * The parseError event is emitted if the driver detects illegal or corrupt BSON being received from the server.
1008
- *
1009
- * @event Db#parseError
1010
- * @type {MongoError }
1011
- */
1012
-
1013
- /**
1014
- * Db fullsetup event, emitted when all servers in the topology have been connected to at start up time.
1015
- *
1016
- * * Server: Emitted when the driver has connected to the single server and has authenticated.
1017
- * * ReplSet: Emitted after the driver has attempted to connect to all replicaset members.
1018
- * * Mongos: Emitted after the driver has attempted to connect to all mongos proxies.
1019
- *
1020
- * @event Db#fullsetup
1021
- * @type {Db }
1022
- */
1023
-
1024
933
// Constants
1025
934
Db . SYSTEM_NAMESPACE_COLLECTION = CONSTANTS . SYSTEM_NAMESPACE_COLLECTION ;
1026
935
Db . SYSTEM_INDEX_COLLECTION = CONSTANTS . SYSTEM_INDEX_COLLECTION ;
0 commit comments