mongodb 3.0.4 → 3.0.8
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 +52 -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 +60 -182
- package/lib/command_cursor.js +11 -34
- package/lib/cursor.js +48 -90
- package/lib/db.js +55 -124
- package/lib/gridfs/grid_store.js +12 -61
- package/lib/mongo_client.js +37 -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 +52 -5
- package/package.json +5 -5
- package/lib/metadata.js +0 -70
- package/yarn.lock +0 -3904
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 (
|
|
@@ -592,7 +573,7 @@ var createCollection = function(self, name, options, callback) {
|
|
|
592
573
|
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
|
|
593
574
|
* @param {boolean} [options.strict=false] Returns an error if the collection does not exist
|
|
594
575
|
* @param {boolean} [options.capped=false] Create a capped collection.
|
|
595
|
-
* @param {boolean} [options.autoIndexId=true] Create an index on the _id field of the document, True by default on MongoDB 2.
|
|
576
|
+
* @param {boolean} [options.autoIndexId=true] DEPRECATED: Create an index on the _id field of the document, True by default on MongoDB 2.6 - 3.0
|
|
596
577
|
* @param {number} [options.size=null] The size of the capped collection in bytes.
|
|
597
578
|
* @param {number} [options.max=null] The maximum number of documents in the capped collection.
|
|
598
579
|
* @param {number} [options.flags=null] Optional. Available for the MMAPv1 storage engine only to set the usePowerOf2Sizes and the noPadding flag.
|
|
@@ -613,11 +594,13 @@ Db.prototype.createCollection = function(name, options, callback) {
|
|
|
613
594
|
options = options || {};
|
|
614
595
|
options.promiseLibrary = options.promiseLibrary || this.s.promiseLibrary;
|
|
615
596
|
|
|
597
|
+
if (options.autoIndexId !== undefined) {
|
|
598
|
+
console.warn('the autoIndexId option is deprecated and will be removed in a future release');
|
|
599
|
+
}
|
|
600
|
+
|
|
616
601
|
return executeOperation(this.s.topology, createCollection, [this, name, options, callback]);
|
|
617
602
|
};
|
|
618
603
|
|
|
619
|
-
define.classMethod('createCollection', { callback: true, promise: true });
|
|
620
|
-
|
|
621
604
|
/**
|
|
622
605
|
* Get all the db statistics.
|
|
623
606
|
*
|
|
@@ -645,8 +628,6 @@ Db.prototype.stats = function(options, callback) {
|
|
|
645
628
|
return this.command(commandObject, options, callback);
|
|
646
629
|
};
|
|
647
630
|
|
|
648
|
-
define.classMethod('stats', { callback: true, promise: true });
|
|
649
|
-
|
|
650
631
|
// Transformation methods for cursor results
|
|
651
632
|
var listCollectionsTranforms = function(databaseName) {
|
|
652
633
|
var matching = f('%s.', databaseName);
|
|
@@ -745,12 +726,6 @@ Db.prototype.listCollections = function(filter, options) {
|
|
|
745
726
|
return cursor;
|
|
746
727
|
};
|
|
747
728
|
|
|
748
|
-
define.classMethod('listCollections', {
|
|
749
|
-
callback: false,
|
|
750
|
-
promise: false,
|
|
751
|
-
returns: [CommandCursor]
|
|
752
|
-
});
|
|
753
|
-
|
|
754
729
|
var evaluate = function(self, code, parameters, options, callback) {
|
|
755
730
|
var finalCode = code;
|
|
756
731
|
var finalParameters = [];
|
|
@@ -814,8 +789,6 @@ Db.prototype.eval = function(code, parameters, options, callback) {
|
|
|
814
789
|
return executeOperation(this.s.topology, evaluate, [this, code, parameters, options, callback]);
|
|
815
790
|
};
|
|
816
791
|
|
|
817
|
-
define.classMethod('eval', { callback: true, promise: true });
|
|
818
|
-
|
|
819
792
|
/**
|
|
820
793
|
* Rename a collection.
|
|
821
794
|
*
|
|
@@ -842,8 +815,6 @@ Db.prototype.renameCollection = function(fromCollection, toCollection, options,
|
|
|
842
815
|
]);
|
|
843
816
|
};
|
|
844
817
|
|
|
845
|
-
define.classMethod('renameCollection', { callback: true, promise: true });
|
|
846
|
-
|
|
847
818
|
/**
|
|
848
819
|
* Drop a collection from the database, removing it permanently. New accesses will create a new collection.
|
|
849
820
|
*
|
|
@@ -862,7 +833,7 @@ Db.prototype.dropCollection = function(name, options, callback) {
|
|
|
862
833
|
var cmd = { drop: name };
|
|
863
834
|
|
|
864
835
|
// Decorate with write concern
|
|
865
|
-
|
|
836
|
+
applyWriteConcern(cmd, { db: this }, options);
|
|
866
837
|
|
|
867
838
|
// options
|
|
868
839
|
const opts = Object.assign({}, this.s.options, { readPreference: ReadPreference.PRIMARY });
|
|
@@ -884,8 +855,6 @@ const dropCollection = (self, cmd, options, callback) => {
|
|
|
884
855
|
});
|
|
885
856
|
};
|
|
886
857
|
|
|
887
|
-
define.classMethod('dropCollection', { callback: true, promise: true });
|
|
888
|
-
|
|
889
858
|
/**
|
|
890
859
|
* Drop a database, removing it permanently from the server.
|
|
891
860
|
*
|
|
@@ -902,14 +871,13 @@ Db.prototype.dropDatabase = function(options, callback) {
|
|
|
902
871
|
var cmd = { dropDatabase: 1 };
|
|
903
872
|
|
|
904
873
|
// Decorate with write concern
|
|
905
|
-
|
|
874
|
+
applyWriteConcern(cmd, { db: this }, options);
|
|
906
875
|
|
|
907
876
|
// Ensure primary only
|
|
908
|
-
const finalOptions = Object.assign(
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
);
|
|
877
|
+
const finalOptions = Object.assign({}, this.s.options, {
|
|
878
|
+
readPreference: ReadPreference.PRIMARY
|
|
879
|
+
});
|
|
880
|
+
|
|
913
881
|
if (options.session) {
|
|
914
882
|
finalOptions.session = options.session;
|
|
915
883
|
}
|
|
@@ -930,8 +898,6 @@ const dropDatabase = (self, cmd, options, callback) => {
|
|
|
930
898
|
});
|
|
931
899
|
};
|
|
932
900
|
|
|
933
|
-
define.classMethod('dropDatabase', { callback: true, promise: true });
|
|
934
|
-
|
|
935
901
|
/**
|
|
936
902
|
* Fetch all collections for the current db.
|
|
937
903
|
*
|
|
@@ -975,8 +941,6 @@ var collections = function(self, options, callback) {
|
|
|
975
941
|
});
|
|
976
942
|
};
|
|
977
943
|
|
|
978
|
-
define.classMethod('collections', { callback: true, promise: true });
|
|
979
|
-
|
|
980
944
|
/**
|
|
981
945
|
* Runs a command on the database as admin.
|
|
982
946
|
* @method
|
|
@@ -1016,8 +980,6 @@ const executeDbAdminCommand = (self, selector, options, callback) => {
|
|
|
1016
980
|
});
|
|
1017
981
|
};
|
|
1018
982
|
|
|
1019
|
-
define.classMethod('executeDbAdminCommand', { callback: true, promise: true });
|
|
1020
|
-
|
|
1021
983
|
/**
|
|
1022
984
|
* Creates an index on the db and collection collection.
|
|
1023
985
|
* @method
|
|
@@ -1057,7 +1019,7 @@ Db.prototype.createIndex = function(name, fieldOrSpec, options, callback) {
|
|
|
1057
1019
|
var createIndex = function(self, name, fieldOrSpec, options, callback) {
|
|
1058
1020
|
// Get the write concern options
|
|
1059
1021
|
var finalOptions = Object.assign({}, { readPreference: ReadPreference.PRIMARY }, options);
|
|
1060
|
-
finalOptions =
|
|
1022
|
+
finalOptions = applyWriteConcern(finalOptions, { db: self }, options);
|
|
1061
1023
|
|
|
1062
1024
|
// Ensure we have a callback
|
|
1063
1025
|
if (finalOptions.writeConcern && typeof callback !== 'function') {
|
|
@@ -1077,11 +1039,18 @@ var createIndex = function(self, name, fieldOrSpec, options, callback) {
|
|
|
1077
1039
|
|
|
1078
1040
|
// 67 = 'CannotCreateIndex' (malformed index options)
|
|
1079
1041
|
// 85 = 'IndexOptionsConflict' (index already exists with different options)
|
|
1042
|
+
// 86 = 'IndexKeySpecsConflict' (index already exists with the same name)
|
|
1080
1043
|
// 11000 = 'DuplicateKey' (couldn't build unique index because of dupes)
|
|
1081
1044
|
// 11600 = 'InterruptedAtShutdown' (interrupted at shutdown)
|
|
1082
1045
|
// These errors mean that the server recognized `createIndex` as a command
|
|
1083
1046
|
// and so we don't need to fallback to an insert.
|
|
1084
|
-
if (
|
|
1047
|
+
if (
|
|
1048
|
+
err.code === 67 ||
|
|
1049
|
+
err.code === 11000 ||
|
|
1050
|
+
err.code === 85 ||
|
|
1051
|
+
err.code === 86 ||
|
|
1052
|
+
err.code === 11600
|
|
1053
|
+
) {
|
|
1085
1054
|
return handleCallback(callback, err, result);
|
|
1086
1055
|
}
|
|
1087
1056
|
|
|
@@ -1106,8 +1075,6 @@ var createIndex = function(self, name, fieldOrSpec, options, callback) {
|
|
|
1106
1075
|
});
|
|
1107
1076
|
};
|
|
1108
1077
|
|
|
1109
|
-
define.classMethod('createIndex', { callback: true, promise: true });
|
|
1110
|
-
|
|
1111
1078
|
/**
|
|
1112
1079
|
* Ensures that an index exists, if it does not it creates it
|
|
1113
1080
|
* @method
|
|
@@ -1146,7 +1113,7 @@ Db.prototype.ensureIndex = function(name, fieldOrSpec, options, callback) {
|
|
|
1146
1113
|
|
|
1147
1114
|
var ensureIndex = function(self, name, fieldOrSpec, options, callback) {
|
|
1148
1115
|
// Get the write concern options
|
|
1149
|
-
var finalOptions =
|
|
1116
|
+
var finalOptions = applyWriteConcern({}, { db: self }, options);
|
|
1150
1117
|
// Create command
|
|
1151
1118
|
var selector = createCreateIndexCommand(self, name, fieldOrSpec, options);
|
|
1152
1119
|
var index_name = selector.name;
|
|
@@ -1170,8 +1137,6 @@ var ensureIndex = function(self, name, fieldOrSpec, options, callback) {
|
|
|
1170
1137
|
});
|
|
1171
1138
|
};
|
|
1172
1139
|
|
|
1173
|
-
define.classMethod('ensureIndex', { callback: true, promise: true });
|
|
1174
|
-
|
|
1175
1140
|
Db.prototype.addChild = function(db) {
|
|
1176
1141
|
if (this.s.parentDb) return this.s.parentDb.addChild(db);
|
|
1177
1142
|
this.s.children.push(db);
|
|
@@ -1233,7 +1198,7 @@ var _executeAuthCreateUserCommand = function(self, username, password, options,
|
|
|
1233
1198
|
};
|
|
1234
1199
|
|
|
1235
1200
|
// Apply write concern to command
|
|
1236
|
-
command =
|
|
1201
|
+
command = applyWriteConcern(command, { db: self }, options);
|
|
1237
1202
|
|
|
1238
1203
|
// Use node md5 generator
|
|
1239
1204
|
var md5 = crypto.createHash('md5');
|
|
@@ -1270,7 +1235,8 @@ var addUser = function(self, username, password, options, callback) {
|
|
|
1270
1235
|
_executeAuthCreateUserCommand(self, username, password, options, function(err, r) {
|
|
1271
1236
|
// We need to perform the backward compatible insert operation
|
|
1272
1237
|
if (err && err.code === -5000) {
|
|
1273
|
-
var finalOptions =
|
|
1238
|
+
var finalOptions = applyWriteConcern(shallowClone(options), { db: self }, options);
|
|
1239
|
+
|
|
1274
1240
|
// Use node md5 generator
|
|
1275
1241
|
var md5 = crypto.createHash('md5');
|
|
1276
1242
|
// Generate keys used for authentication
|
|
@@ -1343,8 +1309,6 @@ Db.prototype.addUser = function(username, password, options, callback) {
|
|
|
1343
1309
|
return executeOperation(this.s.topology, addUser, [this, username, password, options, callback]);
|
|
1344
1310
|
};
|
|
1345
1311
|
|
|
1346
|
-
define.classMethod('addUser', { callback: true, promise: true });
|
|
1347
|
-
|
|
1348
1312
|
var _executeAuthRemoveUserCommand = function(self, username, options, callback) {
|
|
1349
1313
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
1350
1314
|
options = options || {};
|
|
@@ -1368,7 +1332,7 @@ var _executeAuthRemoveUserCommand = function(self, username, options, callback)
|
|
|
1368
1332
|
};
|
|
1369
1333
|
|
|
1370
1334
|
// Apply write concern to command
|
|
1371
|
-
command =
|
|
1335
|
+
command = applyWriteConcern(command, { db: self }, options);
|
|
1372
1336
|
|
|
1373
1337
|
// Force write using primary
|
|
1374
1338
|
commandOptions.readPreference = ReadPreference.primary;
|
|
@@ -1385,7 +1349,7 @@ var removeUser = function(self, username, options, callback) {
|
|
|
1385
1349
|
// Attempt to execute command
|
|
1386
1350
|
_executeAuthRemoveUserCommand(self, username, options, function(err, result) {
|
|
1387
1351
|
if (err && err.code === -5000) {
|
|
1388
|
-
var finalOptions =
|
|
1352
|
+
var finalOptions = applyWriteConcern(shallowClone(options), { db: self }, options);
|
|
1389
1353
|
// If we have another db set
|
|
1390
1354
|
var db = options.dbName ? new Db(options.dbName, self.s.topology, self.s.options) : self;
|
|
1391
1355
|
|
|
@@ -1408,8 +1372,6 @@ var removeUser = function(self, username, options, callback) {
|
|
|
1408
1372
|
});
|
|
1409
1373
|
};
|
|
1410
1374
|
|
|
1411
|
-
define.classMethod('removeUser', { callback: true, promise: true });
|
|
1412
|
-
|
|
1413
1375
|
/**
|
|
1414
1376
|
* Remove a user from a database
|
|
1415
1377
|
* @method
|
|
@@ -1471,8 +1433,6 @@ var setProfilingLevel = function(self, level, options, callback) {
|
|
|
1471
1433
|
});
|
|
1472
1434
|
};
|
|
1473
1435
|
|
|
1474
|
-
define.classMethod('setProfilingLevel', { callback: true, promise: true });
|
|
1475
|
-
|
|
1476
1436
|
/**
|
|
1477
1437
|
* Retrive the current profiling information for MongoDB
|
|
1478
1438
|
*
|
|
@@ -1500,8 +1460,6 @@ var profilingInfo = function(self, options, callback) {
|
|
|
1500
1460
|
}
|
|
1501
1461
|
};
|
|
1502
1462
|
|
|
1503
|
-
define.classMethod('profilingInfo', { callback: true, promise: true });
|
|
1504
|
-
|
|
1505
1463
|
/**
|
|
1506
1464
|
* Retrieve the current profiling Level for MongoDB
|
|
1507
1465
|
*
|
|
@@ -1531,8 +1489,6 @@ var profilingLevel = function(self, options, callback) {
|
|
|
1531
1489
|
});
|
|
1532
1490
|
};
|
|
1533
1491
|
|
|
1534
|
-
define.classMethod('profilingLevel', { callback: true, promise: true });
|
|
1535
|
-
|
|
1536
1492
|
/**
|
|
1537
1493
|
* Retrieves this collections index info.
|
|
1538
1494
|
* @method
|
|
@@ -1587,8 +1543,6 @@ var indexInformation = function(self, name, options, callback) {
|
|
|
1587
1543
|
});
|
|
1588
1544
|
};
|
|
1589
1545
|
|
|
1590
|
-
define.classMethod('indexInformation', { callback: true, promise: true });
|
|
1591
|
-
|
|
1592
1546
|
var createCreateIndexCommand = function(db, name, fieldOrSpec, options) {
|
|
1593
1547
|
var indexParameters = parseIndexOptions(fieldOrSpec);
|
|
1594
1548
|
var fieldHash = indexParameters.fieldHash;
|
|
@@ -1662,10 +1616,7 @@ var createIndexUsingCreateIndexes = function(self, name, fieldOrSpec, options, c
|
|
|
1662
1616
|
}
|
|
1663
1617
|
|
|
1664
1618
|
// Create command, apply write concern to command
|
|
1665
|
-
var cmd =
|
|
1666
|
-
|
|
1667
|
-
// Decorate command with writeConcern if supported
|
|
1668
|
-
decorateWithWriteConcern(cmd, self, options);
|
|
1619
|
+
var cmd = applyWriteConcern({ createIndexes: name, indexes: indexes }, { db: self }, options);
|
|
1669
1620
|
|
|
1670
1621
|
// ReadPreference primary
|
|
1671
1622
|
options.readPreference = ReadPreference.PRIMARY;
|
|
@@ -1697,26 +1648,6 @@ var validateDatabaseName = function(databaseName) {
|
|
|
1697
1648
|
}
|
|
1698
1649
|
};
|
|
1699
1650
|
|
|
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
1651
|
// Add listeners to topology
|
|
1721
1652
|
var createListener = function(self, e, object) {
|
|
1722
1653
|
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
|
*/
|