mongodb 3.0.6 → 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/CODE_OF_CONDUCT.md +80 -0
- package/CONTRIBUTING.md +29 -0
- package/HISTORY.md +5 -0
- package/conf.json +0 -1
- package/lib/admin.js +6 -49
- package/lib/aggregation_cursor.js +4 -45
- 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 +57 -180
- package/lib/command_cursor.js +5 -32
- package/lib/cursor.js +13 -82
- package/lib/db.js +38 -117
- package/lib/gridfs/grid_store.js +12 -61
- package/lib/mongo_client.js +16 -27
- package/lib/topologies/mongos.js +10 -38
- package/lib/topologies/replset.js +10 -37
- package/lib/topologies/server.js +9 -37
- package/lib/utils.js +48 -2
- package/package.json +2 -2
- package/yarn.lock +28 -24
- 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,7 +867,7 @@ 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
873
|
const finalOptions = Object.assign({}, this.s.options, {
|
|
@@ -929,8 +894,6 @@ const dropDatabase = (self, cmd, options, callback) => {
|
|
|
929
894
|
});
|
|
930
895
|
};
|
|
931
896
|
|
|
932
|
-
define.classMethod('dropDatabase', { callback: true, promise: true });
|
|
933
|
-
|
|
934
897
|
/**
|
|
935
898
|
* Fetch all collections for the current db.
|
|
936
899
|
*
|
|
@@ -974,8 +937,6 @@ var collections = function(self, options, callback) {
|
|
|
974
937
|
});
|
|
975
938
|
};
|
|
976
939
|
|
|
977
|
-
define.classMethod('collections', { callback: true, promise: true });
|
|
978
|
-
|
|
979
940
|
/**
|
|
980
941
|
* Runs a command on the database as admin.
|
|
981
942
|
* @method
|
|
@@ -1015,8 +976,6 @@ const executeDbAdminCommand = (self, selector, options, callback) => {
|
|
|
1015
976
|
});
|
|
1016
977
|
};
|
|
1017
978
|
|
|
1018
|
-
define.classMethod('executeDbAdminCommand', { callback: true, promise: true });
|
|
1019
|
-
|
|
1020
979
|
/**
|
|
1021
980
|
* Creates an index on the db and collection collection.
|
|
1022
981
|
* @method
|
|
@@ -1056,7 +1015,7 @@ Db.prototype.createIndex = function(name, fieldOrSpec, options, callback) {
|
|
|
1056
1015
|
var createIndex = function(self, name, fieldOrSpec, options, callback) {
|
|
1057
1016
|
// Get the write concern options
|
|
1058
1017
|
var finalOptions = Object.assign({}, { readPreference: ReadPreference.PRIMARY }, options);
|
|
1059
|
-
finalOptions =
|
|
1018
|
+
finalOptions = applyWriteConcern(finalOptions, { db: self }, options);
|
|
1060
1019
|
|
|
1061
1020
|
// Ensure we have a callback
|
|
1062
1021
|
if (finalOptions.writeConcern && typeof callback !== 'function') {
|
|
@@ -1105,8 +1064,6 @@ var createIndex = function(self, name, fieldOrSpec, options, callback) {
|
|
|
1105
1064
|
});
|
|
1106
1065
|
};
|
|
1107
1066
|
|
|
1108
|
-
define.classMethod('createIndex', { callback: true, promise: true });
|
|
1109
|
-
|
|
1110
1067
|
/**
|
|
1111
1068
|
* Ensures that an index exists, if it does not it creates it
|
|
1112
1069
|
* @method
|
|
@@ -1145,7 +1102,7 @@ Db.prototype.ensureIndex = function(name, fieldOrSpec, options, callback) {
|
|
|
1145
1102
|
|
|
1146
1103
|
var ensureIndex = function(self, name, fieldOrSpec, options, callback) {
|
|
1147
1104
|
// Get the write concern options
|
|
1148
|
-
var finalOptions =
|
|
1105
|
+
var finalOptions = applyWriteConcern({}, { db: self }, options);
|
|
1149
1106
|
// Create command
|
|
1150
1107
|
var selector = createCreateIndexCommand(self, name, fieldOrSpec, options);
|
|
1151
1108
|
var index_name = selector.name;
|
|
@@ -1169,8 +1126,6 @@ var ensureIndex = function(self, name, fieldOrSpec, options, callback) {
|
|
|
1169
1126
|
});
|
|
1170
1127
|
};
|
|
1171
1128
|
|
|
1172
|
-
define.classMethod('ensureIndex', { callback: true, promise: true });
|
|
1173
|
-
|
|
1174
1129
|
Db.prototype.addChild = function(db) {
|
|
1175
1130
|
if (this.s.parentDb) return this.s.parentDb.addChild(db);
|
|
1176
1131
|
this.s.children.push(db);
|
|
@@ -1232,7 +1187,7 @@ var _executeAuthCreateUserCommand = function(self, username, password, options,
|
|
|
1232
1187
|
};
|
|
1233
1188
|
|
|
1234
1189
|
// Apply write concern to command
|
|
1235
|
-
command =
|
|
1190
|
+
command = applyWriteConcern(command, { db: self }, options);
|
|
1236
1191
|
|
|
1237
1192
|
// Use node md5 generator
|
|
1238
1193
|
var md5 = crypto.createHash('md5');
|
|
@@ -1269,7 +1224,8 @@ var addUser = function(self, username, password, options, callback) {
|
|
|
1269
1224
|
_executeAuthCreateUserCommand(self, username, password, options, function(err, r) {
|
|
1270
1225
|
// We need to perform the backward compatible insert operation
|
|
1271
1226
|
if (err && err.code === -5000) {
|
|
1272
|
-
var finalOptions =
|
|
1227
|
+
var finalOptions = applyWriteConcern(shallowClone(options), { db: self }, options);
|
|
1228
|
+
|
|
1273
1229
|
// Use node md5 generator
|
|
1274
1230
|
var md5 = crypto.createHash('md5');
|
|
1275
1231
|
// Generate keys used for authentication
|
|
@@ -1342,8 +1298,6 @@ Db.prototype.addUser = function(username, password, options, callback) {
|
|
|
1342
1298
|
return executeOperation(this.s.topology, addUser, [this, username, password, options, callback]);
|
|
1343
1299
|
};
|
|
1344
1300
|
|
|
1345
|
-
define.classMethod('addUser', { callback: true, promise: true });
|
|
1346
|
-
|
|
1347
1301
|
var _executeAuthRemoveUserCommand = function(self, username, options, callback) {
|
|
1348
1302
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
1349
1303
|
options = options || {};
|
|
@@ -1367,7 +1321,7 @@ var _executeAuthRemoveUserCommand = function(self, username, options, callback)
|
|
|
1367
1321
|
};
|
|
1368
1322
|
|
|
1369
1323
|
// Apply write concern to command
|
|
1370
|
-
command =
|
|
1324
|
+
command = applyWriteConcern(command, { db: self }, options);
|
|
1371
1325
|
|
|
1372
1326
|
// Force write using primary
|
|
1373
1327
|
commandOptions.readPreference = ReadPreference.primary;
|
|
@@ -1384,7 +1338,7 @@ var removeUser = function(self, username, options, callback) {
|
|
|
1384
1338
|
// Attempt to execute command
|
|
1385
1339
|
_executeAuthRemoveUserCommand(self, username, options, function(err, result) {
|
|
1386
1340
|
if (err && err.code === -5000) {
|
|
1387
|
-
var finalOptions =
|
|
1341
|
+
var finalOptions = applyWriteConcern(shallowClone(options), { db: self }, options);
|
|
1388
1342
|
// If we have another db set
|
|
1389
1343
|
var db = options.dbName ? new Db(options.dbName, self.s.topology, self.s.options) : self;
|
|
1390
1344
|
|
|
@@ -1407,8 +1361,6 @@ var removeUser = function(self, username, options, callback) {
|
|
|
1407
1361
|
});
|
|
1408
1362
|
};
|
|
1409
1363
|
|
|
1410
|
-
define.classMethod('removeUser', { callback: true, promise: true });
|
|
1411
|
-
|
|
1412
1364
|
/**
|
|
1413
1365
|
* Remove a user from a database
|
|
1414
1366
|
* @method
|
|
@@ -1470,8 +1422,6 @@ var setProfilingLevel = function(self, level, options, callback) {
|
|
|
1470
1422
|
});
|
|
1471
1423
|
};
|
|
1472
1424
|
|
|
1473
|
-
define.classMethod('setProfilingLevel', { callback: true, promise: true });
|
|
1474
|
-
|
|
1475
1425
|
/**
|
|
1476
1426
|
* Retrive the current profiling information for MongoDB
|
|
1477
1427
|
*
|
|
@@ -1499,8 +1449,6 @@ var profilingInfo = function(self, options, callback) {
|
|
|
1499
1449
|
}
|
|
1500
1450
|
};
|
|
1501
1451
|
|
|
1502
|
-
define.classMethod('profilingInfo', { callback: true, promise: true });
|
|
1503
|
-
|
|
1504
1452
|
/**
|
|
1505
1453
|
* Retrieve the current profiling Level for MongoDB
|
|
1506
1454
|
*
|
|
@@ -1530,8 +1478,6 @@ var profilingLevel = function(self, options, callback) {
|
|
|
1530
1478
|
});
|
|
1531
1479
|
};
|
|
1532
1480
|
|
|
1533
|
-
define.classMethod('profilingLevel', { callback: true, promise: true });
|
|
1534
|
-
|
|
1535
1481
|
/**
|
|
1536
1482
|
* Retrieves this collections index info.
|
|
1537
1483
|
* @method
|
|
@@ -1586,8 +1532,6 @@ var indexInformation = function(self, name, options, callback) {
|
|
|
1586
1532
|
});
|
|
1587
1533
|
};
|
|
1588
1534
|
|
|
1589
|
-
define.classMethod('indexInformation', { callback: true, promise: true });
|
|
1590
|
-
|
|
1591
1535
|
var createCreateIndexCommand = function(db, name, fieldOrSpec, options) {
|
|
1592
1536
|
var indexParameters = parseIndexOptions(fieldOrSpec);
|
|
1593
1537
|
var fieldHash = indexParameters.fieldHash;
|
|
@@ -1661,10 +1605,7 @@ var createIndexUsingCreateIndexes = function(self, name, fieldOrSpec, options, c
|
|
|
1661
1605
|
}
|
|
1662
1606
|
|
|
1663
1607
|
// Create command, apply write concern to command
|
|
1664
|
-
var cmd =
|
|
1665
|
-
|
|
1666
|
-
// Decorate command with writeConcern if supported
|
|
1667
|
-
decorateWithWriteConcern(cmd, self, options);
|
|
1608
|
+
var cmd = applyWriteConcern({ createIndexes: name, indexes: indexes }, { db: self }, options);
|
|
1668
1609
|
|
|
1669
1610
|
// ReadPreference primary
|
|
1670
1611
|
options.readPreference = ReadPreference.PRIMARY;
|
|
@@ -1696,26 +1637,6 @@ var validateDatabaseName = function(databaseName) {
|
|
|
1696
1637
|
}
|
|
1697
1638
|
};
|
|
1698
1639
|
|
|
1699
|
-
// Get write concern
|
|
1700
|
-
var writeConcern = function(target, db, options) {
|
|
1701
|
-
if (options.w != null || options.j != null || options.fsync != null) {
|
|
1702
|
-
var opts = {};
|
|
1703
|
-
if (options.w) opts.w = options.w;
|
|
1704
|
-
if (options.wtimeout) opts.wtimeout = options.wtimeout;
|
|
1705
|
-
if (options.j) opts.j = options.j;
|
|
1706
|
-
if (options.fsync) opts.fsync = options.fsync;
|
|
1707
|
-
target.writeConcern = opts;
|
|
1708
|
-
} else if (
|
|
1709
|
-
db.writeConcern.w != null ||
|
|
1710
|
-
db.writeConcern.j != null ||
|
|
1711
|
-
db.writeConcern.fsync != null
|
|
1712
|
-
) {
|
|
1713
|
-
target.writeConcern = db.writeConcern;
|
|
1714
|
-
}
|
|
1715
|
-
|
|
1716
|
-
return target;
|
|
1717
|
-
};
|
|
1718
|
-
|
|
1719
1640
|
// Add listeners to topology
|
|
1720
1641
|
var createListener = function(self, e, object) {
|
|
1721
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
|
*/
|