mongodb 3.0.3 → 3.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +2 -1
- package/CHANGES_3.0.0.md +28 -0
- package/CODE_OF_CONDUCT.md +80 -0
- package/CONTRIBUTING.md +29 -0
- package/HISTORY.md +61 -0
- package/conf.json +0 -1
- package/index.js +6 -4
- package/lib/admin.js +6 -49
- package/lib/aggregation_cursor.js +7 -46
- package/lib/apm.js +21 -629
- package/lib/bulk/common.js +0 -23
- package/lib/bulk/ordered.js +15 -22
- package/lib/bulk/unordered.js +15 -22
- package/lib/collection.js +59 -182
- package/lib/command_cursor.js +11 -34
- package/lib/cursor.js +48 -90
- package/lib/db.js +42 -122
- package/lib/gridfs/grid_store.js +12 -61
- package/lib/mongo_client.js +40 -31
- package/lib/topologies/mongos.js +47 -41
- package/lib/topologies/replset.js +46 -39
- package/lib/topologies/server.js +46 -40
- package/lib/topologies/topology_base.js +2 -4
- package/lib/url_parser.js +10 -0
- package/lib/utils.js +83 -30
- package/package.json +5 -5
- package/yarn.lock +375 -559
- package/lib/metadata.js +0 -70
package/lib/db.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
3
|
+
const EventEmitter = require('events').EventEmitter;
|
|
4
|
+
const inherits = require('util').inherits;
|
|
5
|
+
const getSingleProperty = require('./utils').getSingleProperty;
|
|
6
|
+
const shallowClone = require('./utils').shallowClone;
|
|
7
|
+
const parseIndexOptions = require('./utils').parseIndexOptions;
|
|
8
|
+
const debugOptions = require('./utils').debugOptions;
|
|
9
|
+
const CommandCursor = require('./command_cursor');
|
|
10
|
+
const handleCallback = require('./utils').handleCallback;
|
|
11
|
+
const filterOptions = require('./utils').filterOptions;
|
|
12
|
+
const toError = require('./utils').toError;
|
|
13
|
+
const ReadPreference = require('mongodb-core').ReadPreference;
|
|
14
|
+
const f = require('util').format;
|
|
15
|
+
const Admin = require('./admin');
|
|
16
|
+
const Code = require('mongodb-core').BSON.Code;
|
|
17
|
+
const MongoError = require('mongodb-core').MongoError;
|
|
18
|
+
const ObjectID = require('mongodb-core').ObjectID;
|
|
19
|
+
const Logger = require('mongodb-core').Logger;
|
|
20
|
+
const Collection = require('./collection');
|
|
21
|
+
const crypto = require('crypto');
|
|
22
|
+
const mergeOptionsAndWriteConcern = require('./utils').mergeOptionsAndWriteConcern;
|
|
23
|
+
const executeOperation = require('./utils').executeOperation;
|
|
24
|
+
const applyWriteConcern = require('./utils').applyWriteConcern;
|
|
25
25
|
|
|
26
26
|
var debugFields = [
|
|
27
27
|
'authSource',
|
|
@@ -65,15 +65,14 @@ var illegalCommandFields = [
|
|
|
65
65
|
*
|
|
66
66
|
* @example
|
|
67
67
|
* const MongoClient = require('mongodb').MongoClient;
|
|
68
|
-
* const test = require('assert');
|
|
69
68
|
* // Connection url
|
|
70
69
|
* const url = 'mongodb://localhost:27017';
|
|
71
70
|
* // Database Name
|
|
72
71
|
* const dbName = 'test';
|
|
73
72
|
* // Connect using MongoClient
|
|
74
73
|
* MongoClient.connect(url, function(err, client) {
|
|
75
|
-
* //
|
|
76
|
-
* const testDb = client.db(
|
|
74
|
+
* // Select the database by name
|
|
75
|
+
* const testDb = client.db(dbName);
|
|
77
76
|
* client.close();
|
|
78
77
|
* });
|
|
79
78
|
*/
|
|
@@ -223,8 +222,6 @@ var Db = function(databaseName, topology, options) {
|
|
|
223
222
|
|
|
224
223
|
inherits(Db, EventEmitter);
|
|
225
224
|
|
|
226
|
-
var define = (Db.define = new Define('Db', Db, false));
|
|
227
|
-
|
|
228
225
|
// Topology
|
|
229
226
|
Object.defineProperty(Db.prototype, 'topology', {
|
|
230
227
|
enumerable: true,
|
|
@@ -360,8 +357,6 @@ Db.prototype.command = function(command, options, callback) {
|
|
|
360
357
|
return executeOperation(this.s.topology, executeCommand, [this, command, options, callback]);
|
|
361
358
|
};
|
|
362
359
|
|
|
363
|
-
define.classMethod('command', { callback: true, promise: true });
|
|
364
|
-
|
|
365
360
|
/**
|
|
366
361
|
* Return the Admin db instance
|
|
367
362
|
* @method
|
|
@@ -371,8 +366,6 @@ Db.prototype.admin = function() {
|
|
|
371
366
|
return new Admin(this, this.s.topology, this.s.promiseLibrary);
|
|
372
367
|
};
|
|
373
368
|
|
|
374
|
-
define.classMethod('admin', { callback: false, promise: false, returns: [Admin] });
|
|
375
|
-
|
|
376
369
|
/**
|
|
377
370
|
* The callback format for the collection method, must be used if strict is specified
|
|
378
371
|
* @callback Db~collectionResultCallback
|
|
@@ -482,23 +475,10 @@ Db.prototype.collection = function(name, options, callback) {
|
|
|
482
475
|
});
|
|
483
476
|
};
|
|
484
477
|
|
|
485
|
-
define.classMethod('collection', { callback: true, promise: false, returns: [Collection] });
|
|
486
|
-
|
|
487
|
-
function decorateWithWriteConcern(command, self, options) {
|
|
488
|
-
// Do we support write concerns 3.4 and higher
|
|
489
|
-
if (self.s.topology.capabilities().commandsTakeWriteConcern) {
|
|
490
|
-
// Get the write concern settings
|
|
491
|
-
var finalOptions = writeConcern(shallowClone(options), self, options);
|
|
492
|
-
// Add the write concern to the command
|
|
493
|
-
if (finalOptions.writeConcern) {
|
|
494
|
-
command.writeConcern = finalOptions.writeConcern;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
|
|
499
478
|
var createCollection = function(self, name, options, callback) {
|
|
500
479
|
// Get the write concern options
|
|
501
|
-
|
|
480
|
+
const finalOptions = applyWriteConcern(shallowClone(options), { db: self }, options);
|
|
481
|
+
|
|
502
482
|
// Did the user destroy the topology
|
|
503
483
|
if (self.serverConfig && self.serverConfig.isDestroyed()) {
|
|
504
484
|
return callback(new MongoError('topology was destroyed'));
|
|
@@ -542,7 +522,8 @@ var createCollection = function(self, name, options, callback) {
|
|
|
542
522
|
var cmd = { create: name };
|
|
543
523
|
|
|
544
524
|
// Decorate command with writeConcern if supported
|
|
545
|
-
|
|
525
|
+
applyWriteConcern(cmd, { db: self }, options);
|
|
526
|
+
|
|
546
527
|
// Add all optional parameters
|
|
547
528
|
for (var n in options) {
|
|
548
529
|
if (
|
|
@@ -616,8 +597,6 @@ Db.prototype.createCollection = function(name, options, callback) {
|
|
|
616
597
|
return executeOperation(this.s.topology, createCollection, [this, name, options, callback]);
|
|
617
598
|
};
|
|
618
599
|
|
|
619
|
-
define.classMethod('createCollection', { callback: true, promise: true });
|
|
620
|
-
|
|
621
600
|
/**
|
|
622
601
|
* Get all the db statistics.
|
|
623
602
|
*
|
|
@@ -645,8 +624,6 @@ Db.prototype.stats = function(options, callback) {
|
|
|
645
624
|
return this.command(commandObject, options, callback);
|
|
646
625
|
};
|
|
647
626
|
|
|
648
|
-
define.classMethod('stats', { callback: true, promise: true });
|
|
649
|
-
|
|
650
627
|
// Transformation methods for cursor results
|
|
651
628
|
var listCollectionsTranforms = function(databaseName) {
|
|
652
629
|
var matching = f('%s.', databaseName);
|
|
@@ -745,12 +722,6 @@ Db.prototype.listCollections = function(filter, options) {
|
|
|
745
722
|
return cursor;
|
|
746
723
|
};
|
|
747
724
|
|
|
748
|
-
define.classMethod('listCollections', {
|
|
749
|
-
callback: false,
|
|
750
|
-
promise: false,
|
|
751
|
-
returns: [CommandCursor]
|
|
752
|
-
});
|
|
753
|
-
|
|
754
725
|
var evaluate = function(self, code, parameters, options, callback) {
|
|
755
726
|
var finalCode = code;
|
|
756
727
|
var finalParameters = [];
|
|
@@ -814,8 +785,6 @@ Db.prototype.eval = function(code, parameters, options, callback) {
|
|
|
814
785
|
return executeOperation(this.s.topology, evaluate, [this, code, parameters, options, callback]);
|
|
815
786
|
};
|
|
816
787
|
|
|
817
|
-
define.classMethod('eval', { callback: true, promise: true });
|
|
818
|
-
|
|
819
788
|
/**
|
|
820
789
|
* Rename a collection.
|
|
821
790
|
*
|
|
@@ -842,8 +811,6 @@ Db.prototype.renameCollection = function(fromCollection, toCollection, options,
|
|
|
842
811
|
]);
|
|
843
812
|
};
|
|
844
813
|
|
|
845
|
-
define.classMethod('renameCollection', { callback: true, promise: true });
|
|
846
|
-
|
|
847
814
|
/**
|
|
848
815
|
* Drop a collection from the database, removing it permanently. New accesses will create a new collection.
|
|
849
816
|
*
|
|
@@ -862,7 +829,7 @@ Db.prototype.dropCollection = function(name, options, callback) {
|
|
|
862
829
|
var cmd = { drop: name };
|
|
863
830
|
|
|
864
831
|
// Decorate with write concern
|
|
865
|
-
|
|
832
|
+
applyWriteConcern(cmd, { db: this }, options);
|
|
866
833
|
|
|
867
834
|
// options
|
|
868
835
|
const opts = Object.assign({}, this.s.options, { readPreference: ReadPreference.PRIMARY });
|
|
@@ -884,8 +851,6 @@ const dropCollection = (self, cmd, options, callback) => {
|
|
|
884
851
|
});
|
|
885
852
|
};
|
|
886
853
|
|
|
887
|
-
define.classMethod('dropCollection', { callback: true, promise: true });
|
|
888
|
-
|
|
889
854
|
/**
|
|
890
855
|
* Drop a database, removing it permanently from the server.
|
|
891
856
|
*
|
|
@@ -902,14 +867,13 @@ Db.prototype.dropDatabase = function(options, callback) {
|
|
|
902
867
|
var cmd = { dropDatabase: 1 };
|
|
903
868
|
|
|
904
869
|
// Decorate with write concern
|
|
905
|
-
|
|
870
|
+
applyWriteConcern(cmd, { db: this }, options);
|
|
906
871
|
|
|
907
872
|
// Ensure primary only
|
|
908
|
-
const finalOptions = Object.assign(
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
);
|
|
873
|
+
const finalOptions = Object.assign({}, this.s.options, {
|
|
874
|
+
readPreference: ReadPreference.PRIMARY
|
|
875
|
+
});
|
|
876
|
+
|
|
913
877
|
if (options.session) {
|
|
914
878
|
finalOptions.session = options.session;
|
|
915
879
|
}
|
|
@@ -930,8 +894,6 @@ const dropDatabase = (self, cmd, options, callback) => {
|
|
|
930
894
|
});
|
|
931
895
|
};
|
|
932
896
|
|
|
933
|
-
define.classMethod('dropDatabase', { callback: true, promise: true });
|
|
934
|
-
|
|
935
897
|
/**
|
|
936
898
|
* Fetch all collections for the current db.
|
|
937
899
|
*
|
|
@@ -975,8 +937,6 @@ var collections = function(self, options, callback) {
|
|
|
975
937
|
});
|
|
976
938
|
};
|
|
977
939
|
|
|
978
|
-
define.classMethod('collections', { callback: true, promise: true });
|
|
979
|
-
|
|
980
940
|
/**
|
|
981
941
|
* Runs a command on the database as admin.
|
|
982
942
|
* @method
|
|
@@ -1016,8 +976,6 @@ const executeDbAdminCommand = (self, selector, options, callback) => {
|
|
|
1016
976
|
});
|
|
1017
977
|
};
|
|
1018
978
|
|
|
1019
|
-
define.classMethod('executeDbAdminCommand', { callback: true, promise: true });
|
|
1020
|
-
|
|
1021
979
|
/**
|
|
1022
980
|
* Creates an index on the db and collection collection.
|
|
1023
981
|
* @method
|
|
@@ -1057,7 +1015,7 @@ Db.prototype.createIndex = function(name, fieldOrSpec, options, callback) {
|
|
|
1057
1015
|
var createIndex = function(self, name, fieldOrSpec, options, callback) {
|
|
1058
1016
|
// Get the write concern options
|
|
1059
1017
|
var finalOptions = Object.assign({}, { readPreference: ReadPreference.PRIMARY }, options);
|
|
1060
|
-
finalOptions =
|
|
1018
|
+
finalOptions = applyWriteConcern(finalOptions, { db: self }, options);
|
|
1061
1019
|
|
|
1062
1020
|
// Ensure we have a callback
|
|
1063
1021
|
if (finalOptions.writeConcern && typeof callback !== 'function') {
|
|
@@ -1106,8 +1064,6 @@ var createIndex = function(self, name, fieldOrSpec, options, callback) {
|
|
|
1106
1064
|
});
|
|
1107
1065
|
};
|
|
1108
1066
|
|
|
1109
|
-
define.classMethod('createIndex', { callback: true, promise: true });
|
|
1110
|
-
|
|
1111
1067
|
/**
|
|
1112
1068
|
* Ensures that an index exists, if it does not it creates it
|
|
1113
1069
|
* @method
|
|
@@ -1146,7 +1102,7 @@ Db.prototype.ensureIndex = function(name, fieldOrSpec, options, callback) {
|
|
|
1146
1102
|
|
|
1147
1103
|
var ensureIndex = function(self, name, fieldOrSpec, options, callback) {
|
|
1148
1104
|
// Get the write concern options
|
|
1149
|
-
var finalOptions =
|
|
1105
|
+
var finalOptions = applyWriteConcern({}, { db: self }, options);
|
|
1150
1106
|
// Create command
|
|
1151
1107
|
var selector = createCreateIndexCommand(self, name, fieldOrSpec, options);
|
|
1152
1108
|
var index_name = selector.name;
|
|
@@ -1170,8 +1126,6 @@ var ensureIndex = function(self, name, fieldOrSpec, options, callback) {
|
|
|
1170
1126
|
});
|
|
1171
1127
|
};
|
|
1172
1128
|
|
|
1173
|
-
define.classMethod('ensureIndex', { callback: true, promise: true });
|
|
1174
|
-
|
|
1175
1129
|
Db.prototype.addChild = function(db) {
|
|
1176
1130
|
if (this.s.parentDb) return this.s.parentDb.addChild(db);
|
|
1177
1131
|
this.s.children.push(db);
|
|
@@ -1233,7 +1187,7 @@ var _executeAuthCreateUserCommand = function(self, username, password, options,
|
|
|
1233
1187
|
};
|
|
1234
1188
|
|
|
1235
1189
|
// Apply write concern to command
|
|
1236
|
-
command =
|
|
1190
|
+
command = applyWriteConcern(command, { db: self }, options);
|
|
1237
1191
|
|
|
1238
1192
|
// Use node md5 generator
|
|
1239
1193
|
var md5 = crypto.createHash('md5');
|
|
@@ -1270,7 +1224,8 @@ var addUser = function(self, username, password, options, callback) {
|
|
|
1270
1224
|
_executeAuthCreateUserCommand(self, username, password, options, function(err, r) {
|
|
1271
1225
|
// We need to perform the backward compatible insert operation
|
|
1272
1226
|
if (err && err.code === -5000) {
|
|
1273
|
-
var finalOptions =
|
|
1227
|
+
var finalOptions = applyWriteConcern(shallowClone(options), { db: self }, options);
|
|
1228
|
+
|
|
1274
1229
|
// Use node md5 generator
|
|
1275
1230
|
var md5 = crypto.createHash('md5');
|
|
1276
1231
|
// Generate keys used for authentication
|
|
@@ -1343,8 +1298,6 @@ Db.prototype.addUser = function(username, password, options, callback) {
|
|
|
1343
1298
|
return executeOperation(this.s.topology, addUser, [this, username, password, options, callback]);
|
|
1344
1299
|
};
|
|
1345
1300
|
|
|
1346
|
-
define.classMethod('addUser', { callback: true, promise: true });
|
|
1347
|
-
|
|
1348
1301
|
var _executeAuthRemoveUserCommand = function(self, username, options, callback) {
|
|
1349
1302
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
1350
1303
|
options = options || {};
|
|
@@ -1368,7 +1321,7 @@ var _executeAuthRemoveUserCommand = function(self, username, options, callback)
|
|
|
1368
1321
|
};
|
|
1369
1322
|
|
|
1370
1323
|
// Apply write concern to command
|
|
1371
|
-
command =
|
|
1324
|
+
command = applyWriteConcern(command, { db: self }, options);
|
|
1372
1325
|
|
|
1373
1326
|
// Force write using primary
|
|
1374
1327
|
commandOptions.readPreference = ReadPreference.primary;
|
|
@@ -1385,7 +1338,7 @@ var removeUser = function(self, username, options, callback) {
|
|
|
1385
1338
|
// Attempt to execute command
|
|
1386
1339
|
_executeAuthRemoveUserCommand(self, username, options, function(err, result) {
|
|
1387
1340
|
if (err && err.code === -5000) {
|
|
1388
|
-
var finalOptions =
|
|
1341
|
+
var finalOptions = applyWriteConcern(shallowClone(options), { db: self }, options);
|
|
1389
1342
|
// If we have another db set
|
|
1390
1343
|
var db = options.dbName ? new Db(options.dbName, self.s.topology, self.s.options) : self;
|
|
1391
1344
|
|
|
@@ -1408,8 +1361,6 @@ var removeUser = function(self, username, options, callback) {
|
|
|
1408
1361
|
});
|
|
1409
1362
|
};
|
|
1410
1363
|
|
|
1411
|
-
define.classMethod('removeUser', { callback: true, promise: true });
|
|
1412
|
-
|
|
1413
1364
|
/**
|
|
1414
1365
|
* Remove a user from a database
|
|
1415
1366
|
* @method
|
|
@@ -1471,8 +1422,6 @@ var setProfilingLevel = function(self, level, options, callback) {
|
|
|
1471
1422
|
});
|
|
1472
1423
|
};
|
|
1473
1424
|
|
|
1474
|
-
define.classMethod('setProfilingLevel', { callback: true, promise: true });
|
|
1475
|
-
|
|
1476
1425
|
/**
|
|
1477
1426
|
* Retrive the current profiling information for MongoDB
|
|
1478
1427
|
*
|
|
@@ -1500,8 +1449,6 @@ var profilingInfo = function(self, options, callback) {
|
|
|
1500
1449
|
}
|
|
1501
1450
|
};
|
|
1502
1451
|
|
|
1503
|
-
define.classMethod('profilingInfo', { callback: true, promise: true });
|
|
1504
|
-
|
|
1505
1452
|
/**
|
|
1506
1453
|
* Retrieve the current profiling Level for MongoDB
|
|
1507
1454
|
*
|
|
@@ -1531,8 +1478,6 @@ var profilingLevel = function(self, options, callback) {
|
|
|
1531
1478
|
});
|
|
1532
1479
|
};
|
|
1533
1480
|
|
|
1534
|
-
define.classMethod('profilingLevel', { callback: true, promise: true });
|
|
1535
|
-
|
|
1536
1481
|
/**
|
|
1537
1482
|
* Retrieves this collections index info.
|
|
1538
1483
|
* @method
|
|
@@ -1587,8 +1532,6 @@ var indexInformation = function(self, name, options, callback) {
|
|
|
1587
1532
|
});
|
|
1588
1533
|
};
|
|
1589
1534
|
|
|
1590
|
-
define.classMethod('indexInformation', { callback: true, promise: true });
|
|
1591
|
-
|
|
1592
1535
|
var createCreateIndexCommand = function(db, name, fieldOrSpec, options) {
|
|
1593
1536
|
var indexParameters = parseIndexOptions(fieldOrSpec);
|
|
1594
1537
|
var fieldHash = indexParameters.fieldHash;
|
|
@@ -1662,10 +1605,7 @@ var createIndexUsingCreateIndexes = function(self, name, fieldOrSpec, options, c
|
|
|
1662
1605
|
}
|
|
1663
1606
|
|
|
1664
1607
|
// Create command, apply write concern to command
|
|
1665
|
-
var cmd =
|
|
1666
|
-
|
|
1667
|
-
// Decorate command with writeConcern if supported
|
|
1668
|
-
decorateWithWriteConcern(cmd, self, options);
|
|
1608
|
+
var cmd = applyWriteConcern({ createIndexes: name, indexes: indexes }, { db: self }, options);
|
|
1669
1609
|
|
|
1670
1610
|
// ReadPreference primary
|
|
1671
1611
|
options.readPreference = ReadPreference.PRIMARY;
|
|
@@ -1697,26 +1637,6 @@ var validateDatabaseName = function(databaseName) {
|
|
|
1697
1637
|
}
|
|
1698
1638
|
};
|
|
1699
1639
|
|
|
1700
|
-
// Get write concern
|
|
1701
|
-
var writeConcern = function(target, db, options) {
|
|
1702
|
-
if (options.w != null || options.j != null || options.fsync != null) {
|
|
1703
|
-
var opts = {};
|
|
1704
|
-
if (options.w) opts.w = options.w;
|
|
1705
|
-
if (options.wtimeout) opts.wtimeout = options.wtimeout;
|
|
1706
|
-
if (options.j) opts.j = options.j;
|
|
1707
|
-
if (options.fsync) opts.fsync = options.fsync;
|
|
1708
|
-
target.writeConcern = opts;
|
|
1709
|
-
} else if (
|
|
1710
|
-
db.writeConcern.w != null ||
|
|
1711
|
-
db.writeConcern.j != null ||
|
|
1712
|
-
db.writeConcern.fsync != null
|
|
1713
|
-
) {
|
|
1714
|
-
target.writeConcern = db.writeConcern;
|
|
1715
|
-
}
|
|
1716
|
-
|
|
1717
|
-
return target;
|
|
1718
|
-
};
|
|
1719
|
-
|
|
1720
1640
|
// Add listeners to topology
|
|
1721
1641
|
var createListener = function(self, e, object) {
|
|
1722
1642
|
var listener = function(err) {
|
package/lib/gridfs/grid_store.js
CHANGED
|
@@ -35,20 +35,18 @@
|
|
|
35
35
|
* });
|
|
36
36
|
* });
|
|
37
37
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
shallowClone = require('../utils').shallowClone,
|
|
51
|
-
executeOperation = require('../utils').executeOperation;
|
|
38
|
+
const Chunk = require('./chunk');
|
|
39
|
+
const ObjectID = require('mongodb-core').BSON.ObjectID;
|
|
40
|
+
const ReadPreference = require('mongodb-core').ReadPreference;
|
|
41
|
+
const Buffer = require('buffer').Buffer;
|
|
42
|
+
const fs = require('fs');
|
|
43
|
+
const f = require('util').format;
|
|
44
|
+
const util = require('util');
|
|
45
|
+
const MongoError = require('mongodb-core').MongoError;
|
|
46
|
+
const inherits = util.inherits;
|
|
47
|
+
const Duplex = require('stream').Duplex;
|
|
48
|
+
const shallowClone = require('../utils').shallowClone;
|
|
49
|
+
const executeOperation = require('../utils').executeOperation;
|
|
52
50
|
|
|
53
51
|
var REFERENCE_BY_FILENAME = 0,
|
|
54
52
|
REFERENCE_BY_ID = 1;
|
|
@@ -174,8 +172,6 @@ var GridStore = function GridStore(db, id, filename, mode, options) {
|
|
|
174
172
|
});
|
|
175
173
|
};
|
|
176
174
|
|
|
177
|
-
var define = (GridStore.define = new Define('Gridstore', GridStore, true));
|
|
178
|
-
|
|
179
175
|
/**
|
|
180
176
|
* The callback format for the Gridstore.open method
|
|
181
177
|
* @callback GridStore~openCallback
|
|
@@ -242,9 +238,6 @@ var open = function(self, options, callback) {
|
|
|
242
238
|
}
|
|
243
239
|
};
|
|
244
240
|
|
|
245
|
-
// Push the definition for open
|
|
246
|
-
define.classMethod('open', { callback: true, promise: true });
|
|
247
|
-
|
|
248
241
|
/**
|
|
249
242
|
* Verify if the file is at EOF.
|
|
250
243
|
*
|
|
@@ -256,8 +249,6 @@ GridStore.prototype.eof = function() {
|
|
|
256
249
|
return this.position === this.length ? true : false;
|
|
257
250
|
};
|
|
258
251
|
|
|
259
|
-
define.classMethod('eof', { callback: false, promise: false, returns: [Boolean] });
|
|
260
|
-
|
|
261
252
|
/**
|
|
262
253
|
* The callback result format.
|
|
263
254
|
* @callback GridStore~resultCallback
|
|
@@ -299,8 +290,6 @@ var getc = function(self, options, callback) {
|
|
|
299
290
|
}
|
|
300
291
|
};
|
|
301
292
|
|
|
302
|
-
define.classMethod('getc', { callback: true, promise: true });
|
|
303
|
-
|
|
304
293
|
/**
|
|
305
294
|
* Writes a string to the file with a newline character appended at the end if
|
|
306
295
|
* the given string does not have one.
|
|
@@ -326,8 +315,6 @@ GridStore.prototype.puts = function(string, options, callback) {
|
|
|
326
315
|
);
|
|
327
316
|
};
|
|
328
317
|
|
|
329
|
-
define.classMethod('puts', { callback: true, promise: true });
|
|
330
|
-
|
|
331
318
|
/**
|
|
332
319
|
* Return a modified Readable stream including a possible transform method.
|
|
333
320
|
*
|
|
@@ -339,8 +326,6 @@ GridStore.prototype.stream = function() {
|
|
|
339
326
|
return new GridStoreStream(this);
|
|
340
327
|
};
|
|
341
328
|
|
|
342
|
-
define.classMethod('stream', { callback: false, promise: false, returns: [GridStoreStream] });
|
|
343
|
-
|
|
344
329
|
/**
|
|
345
330
|
* Writes some data. This method will work properly only if initialized with mode "w" or "w+".
|
|
346
331
|
*
|
|
@@ -365,8 +350,6 @@ GridStore.prototype.write = function write(data, close, options, callback) {
|
|
|
365
350
|
);
|
|
366
351
|
};
|
|
367
352
|
|
|
368
|
-
define.classMethod('write', { callback: true, promise: true });
|
|
369
|
-
|
|
370
353
|
/**
|
|
371
354
|
* Handles the destroy part of a stream
|
|
372
355
|
*
|
|
@@ -385,8 +368,6 @@ GridStore.prototype.destroy = function destroy() {
|
|
|
385
368
|
}
|
|
386
369
|
};
|
|
387
370
|
|
|
388
|
-
define.classMethod('destroy', { callback: false, promise: false });
|
|
389
|
-
|
|
390
371
|
/**
|
|
391
372
|
* Stores a file from the file system to the GridFS database.
|
|
392
373
|
*
|
|
@@ -471,8 +452,6 @@ var writeFile = function(self, file, options, callback) {
|
|
|
471
452
|
});
|
|
472
453
|
};
|
|
473
454
|
|
|
474
|
-
define.classMethod('writeFile', { callback: true, promise: true });
|
|
475
|
-
|
|
476
455
|
/**
|
|
477
456
|
* Saves this file to the database. This will overwrite the old entry if it
|
|
478
457
|
* already exists. This will work properly only if mode was initialized to
|
|
@@ -558,8 +537,6 @@ var close = function(self, options, callback) {
|
|
|
558
537
|
}
|
|
559
538
|
};
|
|
560
539
|
|
|
561
|
-
define.classMethod('close', { callback: true, promise: true });
|
|
562
|
-
|
|
563
540
|
/**
|
|
564
541
|
* The collection callback format.
|
|
565
542
|
* @callback GridStore~collectionCallback
|
|
@@ -580,8 +557,6 @@ GridStore.prototype.chunkCollection = function(callback) {
|
|
|
580
557
|
return this.db.collection(this.root + '.chunks');
|
|
581
558
|
};
|
|
582
559
|
|
|
583
|
-
define.classMethod('chunkCollection', { callback: true, promise: false, returns: [Collection] });
|
|
584
|
-
|
|
585
560
|
/**
|
|
586
561
|
* Deletes all the chunks of this file in the database.
|
|
587
562
|
*
|
|
@@ -621,8 +596,6 @@ var unlink = function(self, options, callback) {
|
|
|
621
596
|
});
|
|
622
597
|
};
|
|
623
598
|
|
|
624
|
-
define.classMethod('unlink', { callback: true, promise: true });
|
|
625
|
-
|
|
626
599
|
/**
|
|
627
600
|
* Retrieves the file collection associated with this object.
|
|
628
601
|
*
|
|
@@ -636,8 +609,6 @@ GridStore.prototype.collection = function(callback) {
|
|
|
636
609
|
return this.db.collection(this.root + '.files');
|
|
637
610
|
};
|
|
638
611
|
|
|
639
|
-
define.classMethod('collection', { callback: true, promise: false, returns: [Collection] });
|
|
640
|
-
|
|
641
612
|
/**
|
|
642
613
|
* The readlines callback format.
|
|
643
614
|
* @callback GridStore~readlinesCallback
|
|
@@ -682,8 +653,6 @@ var readlines = function(self, separator, options, callback) {
|
|
|
682
653
|
});
|
|
683
654
|
};
|
|
684
655
|
|
|
685
|
-
define.classMethod('readlines', { callback: true, promise: true });
|
|
686
|
-
|
|
687
656
|
/**
|
|
688
657
|
* Deletes all the chunks of this file in the database if mode was set to "w" or
|
|
689
658
|
* "w+" and resets the read/write head to the initial position.
|
|
@@ -729,8 +698,6 @@ var rewind = function(self, options, callback) {
|
|
|
729
698
|
}
|
|
730
699
|
};
|
|
731
700
|
|
|
732
|
-
define.classMethod('rewind', { callback: true, promise: true });
|
|
733
|
-
|
|
734
701
|
/**
|
|
735
702
|
* The read callback format.
|
|
736
703
|
* @callback GridStore~readCallback
|
|
@@ -818,8 +785,6 @@ var read = function(self, length, buffer, options, callback) {
|
|
|
818
785
|
});
|
|
819
786
|
};
|
|
820
787
|
|
|
821
|
-
define.classMethod('read', { callback: true, promise: true });
|
|
822
|
-
|
|
823
788
|
/**
|
|
824
789
|
* The tell callback format.
|
|
825
790
|
* @callback GridStore~tellCallback
|
|
@@ -849,8 +814,6 @@ GridStore.prototype.tell = function(callback) {
|
|
|
849
814
|
});
|
|
850
815
|
};
|
|
851
816
|
|
|
852
|
-
define.classMethod('tell', { callback: true, promise: true });
|
|
853
|
-
|
|
854
817
|
/**
|
|
855
818
|
* The tell callback format.
|
|
856
819
|
* @callback GridStore~gridStoreCallback
|
|
@@ -930,8 +893,6 @@ var seek = function(self, position, seekLocation, options, callback) {
|
|
|
930
893
|
seekChunk();
|
|
931
894
|
};
|
|
932
895
|
|
|
933
|
-
define.classMethod('seek', { callback: true, promise: true });
|
|
934
|
-
|
|
935
896
|
/**
|
|
936
897
|
* @ignore
|
|
937
898
|
*/
|
|
@@ -1360,8 +1321,6 @@ var exists = function(db, fileIdObject, rootCollection, options, callback) {
|
|
|
1360
1321
|
});
|
|
1361
1322
|
};
|
|
1362
1323
|
|
|
1363
|
-
define.staticMethod('exist', { callback: true, promise: true });
|
|
1364
|
-
|
|
1365
1324
|
/**
|
|
1366
1325
|
* Gets the list of files stored in the GridFS.
|
|
1367
1326
|
*
|
|
@@ -1421,8 +1380,6 @@ var list = function(db, rootCollection, options, callback) {
|
|
|
1421
1380
|
});
|
|
1422
1381
|
};
|
|
1423
1382
|
|
|
1424
|
-
define.staticMethod('list', { callback: true, promise: true });
|
|
1425
|
-
|
|
1426
1383
|
/**
|
|
1427
1384
|
* Reads the contents of a file.
|
|
1428
1385
|
*
|
|
@@ -1485,8 +1442,6 @@ var readStatic = function(db, name, length, offset, options, callback) {
|
|
|
1485
1442
|
});
|
|
1486
1443
|
};
|
|
1487
1444
|
|
|
1488
|
-
define.staticMethod('read', { callback: true, promise: true });
|
|
1489
|
-
|
|
1490
1445
|
/**
|
|
1491
1446
|
* Read the entire file as a list of strings splitting by the provided separator.
|
|
1492
1447
|
*
|
|
@@ -1526,8 +1481,6 @@ var readlinesStatic = function(db, name, separator, options, callback) {
|
|
|
1526
1481
|
});
|
|
1527
1482
|
};
|
|
1528
1483
|
|
|
1529
|
-
define.staticMethod('readlines', { callback: true, promise: true });
|
|
1530
|
-
|
|
1531
1484
|
/**
|
|
1532
1485
|
* Deletes the chunks and metadata information of a file from GridFS.
|
|
1533
1486
|
*
|
|
@@ -1584,8 +1537,6 @@ var unlinkStatic = function(self, db, names, options, callback) {
|
|
|
1584
1537
|
}
|
|
1585
1538
|
};
|
|
1586
1539
|
|
|
1587
|
-
define.staticMethod('unlink', { callback: true, promise: true });
|
|
1588
|
-
|
|
1589
1540
|
/**
|
|
1590
1541
|
* @ignore
|
|
1591
1542
|
*/
|