mongodb 2.1.0-alpha → 2.1.2
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/HISTORY.md +574 -429
- package/Makefile +2 -5
- package/README.md +108 -15
- package/conf.json +17 -13
- package/index.js +13 -2
- package/lib/admin.js +113 -47
- package/lib/aggregation_cursor.js +56 -28
- package/lib/apm.js +608 -0
- package/lib/bulk/common.js +7 -7
- package/lib/bulk/ordered.js +56 -17
- package/lib/bulk/unordered.js +52 -14
- package/lib/collection.js +671 -212
- package/lib/command_cursor.js +60 -32
- package/lib/cursor.js +313 -115
- package/lib/db.js +264 -105
- package/lib/gridfs/chunk.js +26 -29
- package/lib/gridfs/grid_store.js +150 -64
- package/lib/gridfs-stream/download.js +310 -0
- package/lib/gridfs-stream/index.js +335 -0
- package/lib/gridfs-stream/upload.js +450 -0
- package/lib/metadata.js +64 -0
- package/lib/mongo_client.js +69 -39
- package/lib/mongos.js +65 -20
- package/lib/replset.js +69 -34
- package/lib/server.js +35 -1
- package/lib/topology_base.js +22 -10
- package/lib/url_parser.js +111 -13
- package/lib/utils.js +9 -8
- package/mongolabs.js +427 -0
- package/package.json +8 -6
- package/t.js +68 -51
- package/test.js +12 -0
- package/test_boot/boot.sh +3 -0
- package/test_boot/ca.pem +49 -0
- package/test_boot/client.pem +48 -0
- package/test_boot/client_password.pem +51 -0
- package/test_boot/connect.js +29 -0
- package/test_boot/data/WiredTiger +2 -0
- package/test_boot/data/WiredTiger.lock +1 -0
- package/test_boot/data/WiredTiger.turtle +6 -0
- package/test_boot/data/WiredTiger.wt +0 -0
- package/test_boot/data/WiredTigerLAS.wt +0 -0
- package/test_boot/data/_mdb_catalog.wt +0 -0
- package/test_boot/data/collection-0-757073248613337118.wt +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-44-37Z-00000 +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-45-15Z-00000 +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-46-31Z-00000 +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-47-25Z-00000 +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-49-07Z-00000 +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-50-41Z-00000 +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-50-53Z-00000 +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-52-31Z-00000 +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-54-53Z-00000 +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-55-09Z-00000 +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-55-38Z-00000 +0 -0
- package/test_boot/data/index-1-757073248613337118.wt +0 -0
- package/test_boot/data/mongod.lock +0 -0
- package/test_boot/data/sizeStorer.wt +0 -0
- package/test_boot/data/storage.bson +0 -0
- package/test_boot/server_password.pem +51 -0
- package/.travis.yml +0 -10
- package/t1.js +0 -59
- package/wercker.yml +0 -19
package/lib/gridfs/grid_store.js
CHANGED
|
@@ -38,13 +38,16 @@ var Chunk = require('./chunk'),
|
|
|
38
38
|
ObjectID = require('mongodb-core').BSON.ObjectID,
|
|
39
39
|
ReadPreference = require('../read_preference'),
|
|
40
40
|
Buffer = require('buffer').Buffer,
|
|
41
|
+
Collection = require('../collection'),
|
|
41
42
|
fs = require('fs'),
|
|
42
43
|
timers = require('timers'),
|
|
43
44
|
f = require('util').format,
|
|
44
45
|
util = require('util'),
|
|
46
|
+
Define = require('../metadata'),
|
|
45
47
|
MongoError = require('mongodb-core').MongoError,
|
|
46
48
|
inherits = util.inherits,
|
|
47
|
-
Duplex = require('stream').Duplex || require('readable-stream').Duplex
|
|
49
|
+
Duplex = require('stream').Duplex || require('readable-stream').Duplex,
|
|
50
|
+
shallowClone = require('../utils').shallowClone;
|
|
48
51
|
|
|
49
52
|
var REFERENCE_BY_FILENAME = 0,
|
|
50
53
|
REFERENCE_BY_ID = 1;
|
|
@@ -81,6 +84,7 @@ var REFERENCE_BY_FILENAME = 0,
|
|
|
81
84
|
* @property {number} md5 The md5 checksum for this file.
|
|
82
85
|
* @property {number} chunkNumber The current chunk number the gridstore has materialized into memory
|
|
83
86
|
* @return {GridStore} a GridStore instance.
|
|
87
|
+
* @deprecated Use GridFSBucket API instead
|
|
84
88
|
*/
|
|
85
89
|
var GridStore = function GridStore(db, id, filename, mode, options) {
|
|
86
90
|
if(!(this instanceof GridStore)) return new GridStore(db, id, filename, mode, options);
|
|
@@ -125,7 +129,7 @@ var GridStore = function GridStore(db, id, filename, mode, options) {
|
|
|
125
129
|
// Set the root if overridden
|
|
126
130
|
this.root = this.options['root'] == null ? GridStore.DEFAULT_ROOT_COLLECTION : this.options['root'];
|
|
127
131
|
this.position = 0;
|
|
128
|
-
this.readPreference = this.options.readPreference || ReadPreference.PRIMARY;
|
|
132
|
+
this.readPreference = this.options.readPreference || db.options.readPreference || ReadPreference.PRIMARY;
|
|
129
133
|
this.writeConcern = _getWriteConcern(db, this.options);
|
|
130
134
|
// Set default chunk size
|
|
131
135
|
this.internalChunkSize = this.options['chunkSize'] == null ? Chunk.DEFAULT_CHUNK_SIZE : this.options['chunkSize'];
|
|
@@ -168,6 +172,8 @@ var GridStore = function GridStore(db, id, filename, mode, options) {
|
|
|
168
172
|
});
|
|
169
173
|
}
|
|
170
174
|
|
|
175
|
+
var define = GridStore.define = new Define('Gridstore', GridStore, true);
|
|
176
|
+
|
|
171
177
|
/**
|
|
172
178
|
* The callback format for the Gridstore.open method
|
|
173
179
|
* @callback GridStore~openCallback
|
|
@@ -180,13 +186,14 @@ var GridStore = function GridStore(db, id, filename, mode, options) {
|
|
|
180
186
|
* new one if file does not exist.
|
|
181
187
|
*
|
|
182
188
|
* @method
|
|
183
|
-
* @param {GridStore~openCallback} callback this will be called after executing this method
|
|
189
|
+
* @param {GridStore~openCallback} [callback] this will be called after executing this method
|
|
184
190
|
* @return {Promise} returns Promise if no callback passed
|
|
191
|
+
* @deprecated Use GridFSBucket API instead
|
|
185
192
|
*/
|
|
186
193
|
GridStore.prototype.open = function(callback) {
|
|
187
194
|
var self = this;
|
|
188
195
|
if( this.mode != "w" && this.mode != "w+" && this.mode != "r"){
|
|
189
|
-
throw
|
|
196
|
+
throw MongoError.create({message: "Illegal mode " + this.mode, driver:true});
|
|
190
197
|
}
|
|
191
198
|
|
|
192
199
|
// We provided a callback leg
|
|
@@ -197,7 +204,7 @@ GridStore.prototype.open = function(callback) {
|
|
|
197
204
|
if(err) return reject(err);
|
|
198
205
|
resolve(store);
|
|
199
206
|
})
|
|
200
|
-
});
|
|
207
|
+
});
|
|
201
208
|
};
|
|
202
209
|
|
|
203
210
|
var open = function(self, callback) {
|
|
@@ -212,8 +219,11 @@ var open = function(self, callback) {
|
|
|
212
219
|
collection.ensureIndex([['filename', 1]], writeConcern, function(err, index) {
|
|
213
220
|
// Get chunk collection
|
|
214
221
|
var chunkCollection = self.chunkCollection();
|
|
222
|
+
// Make an unique index for compatibility with mongo-cxx-driver:legacy
|
|
223
|
+
var chunkIndexOptions = shallowClone(writeConcern);
|
|
224
|
+
chunkIndexOptions.unique = true;
|
|
215
225
|
// Ensure index on chunk collection
|
|
216
|
-
chunkCollection.ensureIndex([['files_id', 1], ['n', 1]],
|
|
226
|
+
chunkCollection.ensureIndex([['files_id', 1], ['n', 1]], chunkIndexOptions, function(err, index) {
|
|
217
227
|
// Open the connection
|
|
218
228
|
_open(self, writeConcern, function(err, r) {
|
|
219
229
|
if(err) return callback(err);
|
|
@@ -229,19 +239,25 @@ var open = function(self, callback) {
|
|
|
229
239
|
self.isOpen = true;
|
|
230
240
|
callback(err, r);
|
|
231
241
|
});
|
|
232
|
-
}
|
|
242
|
+
}
|
|
233
243
|
}
|
|
234
244
|
|
|
245
|
+
// Push the definition for open
|
|
246
|
+
define.classMethod('open', {callback: true, promise:true});
|
|
247
|
+
|
|
235
248
|
/**
|
|
236
249
|
* Verify if the file is at EOF.
|
|
237
250
|
*
|
|
238
251
|
* @method
|
|
239
252
|
* @return {boolean} true if the read/write head is at the end of this file.
|
|
253
|
+
* @deprecated Use GridFSBucket API instead
|
|
240
254
|
*/
|
|
241
255
|
GridStore.prototype.eof = function() {
|
|
242
256
|
return this.position == this.length ? true : false;
|
|
243
257
|
}
|
|
244
258
|
|
|
259
|
+
define.classMethod('eof', {callback: false, promise:false, returns: [Boolean]});
|
|
260
|
+
|
|
245
261
|
/**
|
|
246
262
|
* The callback result format.
|
|
247
263
|
* @callback GridStore~resultCallback
|
|
@@ -253,8 +269,9 @@ GridStore.prototype.eof = function() {
|
|
|
253
269
|
* Retrieves a single character from this file.
|
|
254
270
|
*
|
|
255
271
|
* @method
|
|
256
|
-
* @param {GridStore~resultCallback} callback this gets called after this method is executed. Passes null to the first parameter and the character read to the second or null to the second if the read/write head is at the end of the file.
|
|
272
|
+
* @param {GridStore~resultCallback} [callback] this gets called after this method is executed. Passes null to the first parameter and the character read to the second or null to the second if the read/write head is at the end of the file.
|
|
257
273
|
* @return {Promise} returns Promise if no callback passed
|
|
274
|
+
* @deprecated Use GridFSBucket API instead
|
|
258
275
|
*/
|
|
259
276
|
GridStore.prototype.getc = function(callback) {
|
|
260
277
|
var self = this;
|
|
@@ -281,17 +298,20 @@ var eof = function(self, callback) {
|
|
|
281
298
|
} else {
|
|
282
299
|
self.position = self.position + 1;
|
|
283
300
|
callback(null, self.currentChunk.getc());
|
|
284
|
-
}
|
|
301
|
+
}
|
|
285
302
|
}
|
|
286
303
|
|
|
304
|
+
define.classMethod('getc', {callback: true, promise:true});
|
|
305
|
+
|
|
287
306
|
/**
|
|
288
307
|
* Writes a string to the file with a newline character appended at the end if
|
|
289
308
|
* the given string does not have one.
|
|
290
309
|
*
|
|
291
310
|
* @method
|
|
292
311
|
* @param {string} string the string to write.
|
|
293
|
-
* @param {GridStore~resultCallback} callback this will be called after executing this method. The first parameter will contain null and the second one will contain a reference to this object.
|
|
312
|
+
* @param {GridStore~resultCallback} [callback] this will be called after executing this method. The first parameter will contain null and the second one will contain a reference to this object.
|
|
294
313
|
* @return {Promise} returns Promise if no callback passed
|
|
314
|
+
* @deprecated Use GridFSBucket API instead
|
|
295
315
|
*/
|
|
296
316
|
GridStore.prototype.puts = function(string, callback) {
|
|
297
317
|
var self = this;
|
|
@@ -307,24 +327,30 @@ GridStore.prototype.puts = function(string, callback) {
|
|
|
307
327
|
});
|
|
308
328
|
}
|
|
309
329
|
|
|
330
|
+
define.classMethod('puts', {callback: true, promise:true});
|
|
331
|
+
|
|
310
332
|
/**
|
|
311
333
|
* Return a modified Readable stream including a possible transform method.
|
|
312
334
|
*
|
|
313
335
|
* @method
|
|
314
336
|
* @return {GridStoreStream}
|
|
337
|
+
* @deprecated Use GridFSBucket API instead
|
|
315
338
|
*/
|
|
316
339
|
GridStore.prototype.stream = function() {
|
|
317
340
|
return new GridStoreStream(this);
|
|
318
341
|
}
|
|
319
342
|
|
|
343
|
+
define.classMethod('stream', {callback: false, promise:false, returns: [GridStoreStream]});
|
|
344
|
+
|
|
320
345
|
/**
|
|
321
346
|
* Writes some data. This method will work properly only if initialized with mode "w" or "w+".
|
|
322
347
|
*
|
|
323
348
|
* @method
|
|
324
349
|
* @param {(string|Buffer)} data the data to write.
|
|
325
350
|
* @param {boolean} [close] closes this file after writing if set to true.
|
|
326
|
-
* @param {GridStore~resultCallback} callback this will be called after executing this method. The first parameter will contain null and the second one will contain a reference to this object.
|
|
351
|
+
* @param {GridStore~resultCallback} [callback] this will be called after executing this method. The first parameter will contain null and the second one will contain a reference to this object.
|
|
327
352
|
* @return {Promise} returns Promise if no callback passed
|
|
353
|
+
* @deprecated Use GridFSBucket API instead
|
|
328
354
|
*/
|
|
329
355
|
GridStore.prototype.write = function write(data, close, callback) {
|
|
330
356
|
var self = this;
|
|
@@ -339,11 +365,14 @@ GridStore.prototype.write = function write(data, close, callback) {
|
|
|
339
365
|
});
|
|
340
366
|
}
|
|
341
367
|
|
|
368
|
+
define.classMethod('write', {callback: true, promise:true});
|
|
369
|
+
|
|
342
370
|
/**
|
|
343
371
|
* Handles the destroy part of a stream
|
|
344
372
|
*
|
|
345
373
|
* @method
|
|
346
374
|
* @result {null}
|
|
375
|
+
* @deprecated Use GridFSBucket API instead
|
|
347
376
|
*/
|
|
348
377
|
GridStore.prototype.destroy = function destroy() {
|
|
349
378
|
// close and do not emit any more events. queued data is not sent.
|
|
@@ -356,13 +385,16 @@ GridStore.prototype.destroy = function destroy() {
|
|
|
356
385
|
}
|
|
357
386
|
}
|
|
358
387
|
|
|
388
|
+
define.classMethod('destroy', {callback: false, promise:false});
|
|
389
|
+
|
|
359
390
|
/**
|
|
360
391
|
* Stores a file from the file system to the GridFS database.
|
|
361
392
|
*
|
|
362
393
|
* @method
|
|
363
394
|
* @param {(string|Buffer|FileHandle)} file the file to store.
|
|
364
|
-
* @param {GridStore~resultCallback} callback this will be called after executing this method. The first parameter will contain null and the second one will contain a reference to this object.
|
|
395
|
+
* @param {GridStore~resultCallback} [callback] this will be called after executing this method. The first parameter will contain null and the second one will contain a reference to this object.
|
|
365
396
|
* @return {Promise} returns Promise if no callback passed
|
|
397
|
+
* @deprecated Use GridFSBucket API instead
|
|
366
398
|
*/
|
|
367
399
|
GridStore.prototype.writeFile = function (file, callback) {
|
|
368
400
|
var self = this;
|
|
@@ -433,17 +465,20 @@ var writeFile = function(self, file, callback) {
|
|
|
433
465
|
// Process the first write
|
|
434
466
|
process.nextTick(writeChunk);
|
|
435
467
|
});
|
|
436
|
-
});
|
|
468
|
+
});
|
|
437
469
|
}
|
|
438
470
|
|
|
471
|
+
define.classMethod('writeFile', {callback: true, promise:true});
|
|
472
|
+
|
|
439
473
|
/**
|
|
440
474
|
* Saves this file to the database. This will overwrite the old entry if it
|
|
441
475
|
* already exists. This will work properly only if mode was initialized to
|
|
442
476
|
* "w" or "w+".
|
|
443
477
|
*
|
|
444
478
|
* @method
|
|
445
|
-
* @param {GridStore~resultCallback} callback this will be called after executing this method. The first parameter will contain null and the second one will contain a reference to this object.
|
|
479
|
+
* @param {GridStore~resultCallback} [callback] this will be called after executing this method. The first parameter will contain null and the second one will contain a reference to this object.
|
|
446
480
|
* @return {Promise} returns Promise if no callback passed
|
|
481
|
+
* @deprecated Use GridFSBucket API instead
|
|
447
482
|
*/
|
|
448
483
|
GridStore.prototype.close = function(callback) {
|
|
449
484
|
var self = this;
|
|
@@ -472,18 +507,14 @@ var close = function(self, callback) {
|
|
|
472
507
|
|
|
473
508
|
// Build the mongo object
|
|
474
509
|
if(self.uploadDate != null) {
|
|
475
|
-
|
|
476
|
-
if(err
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
if(err) {
|
|
480
|
-
if(typeof callback == 'function') return callback(err); else throw err;
|
|
481
|
-
}
|
|
510
|
+
buildMongoObject(self, function(err, mongoObject) {
|
|
511
|
+
if(err) {
|
|
512
|
+
if(typeof callback == 'function') return callback(err); else throw err;
|
|
513
|
+
}
|
|
482
514
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
});
|
|
515
|
+
files.save(mongoObject, options, function(err) {
|
|
516
|
+
if(typeof callback == 'function')
|
|
517
|
+
callback(err, mongoObject);
|
|
487
518
|
});
|
|
488
519
|
});
|
|
489
520
|
} else {
|
|
@@ -523,10 +554,12 @@ var close = function(self, callback) {
|
|
|
523
554
|
callback(null, null);
|
|
524
555
|
} else {
|
|
525
556
|
if(typeof callback == 'function')
|
|
526
|
-
callback(
|
|
527
|
-
}
|
|
557
|
+
callback(MongoError.create({message: f("Illegal mode %s", self.mode), driver:true}));
|
|
558
|
+
}
|
|
528
559
|
}
|
|
529
560
|
|
|
561
|
+
define.classMethod('close', {callback: true, promise:true});
|
|
562
|
+
|
|
530
563
|
/**
|
|
531
564
|
* The collection callback format.
|
|
532
565
|
* @callback GridStore~collectionCallback
|
|
@@ -540,6 +573,7 @@ var close = function(self, callback) {
|
|
|
540
573
|
* @method
|
|
541
574
|
* @param {GridStore~collectionCallback} callback the command callback.
|
|
542
575
|
* @return {Collection}
|
|
576
|
+
* @deprecated Use GridFSBucket API instead
|
|
543
577
|
*/
|
|
544
578
|
GridStore.prototype.chunkCollection = function(callback) {
|
|
545
579
|
if(typeof callback == 'function')
|
|
@@ -547,12 +581,15 @@ GridStore.prototype.chunkCollection = function(callback) {
|
|
|
547
581
|
return this.db.collection((this.root + ".chunks"));
|
|
548
582
|
};
|
|
549
583
|
|
|
584
|
+
define.classMethod('chunkCollection', {callback: true, promise:false, returns: [Collection]});
|
|
585
|
+
|
|
550
586
|
/**
|
|
551
587
|
* Deletes all the chunks of this file in the database.
|
|
552
588
|
*
|
|
553
589
|
* @method
|
|
554
|
-
* @param {GridStore~resultCallback} callback the command callback.
|
|
590
|
+
* @param {GridStore~resultCallback} [callback] the command callback.
|
|
555
591
|
* @return {Promise} returns Promise if no callback passed
|
|
592
|
+
* @deprecated Use GridFSBucket API instead
|
|
556
593
|
*/
|
|
557
594
|
GridStore.prototype.unlink = function(callback) {
|
|
558
595
|
var self = this;
|
|
@@ -584,15 +621,18 @@ var unlink = function(self, callback) {
|
|
|
584
621
|
callback(err, self);
|
|
585
622
|
});
|
|
586
623
|
});
|
|
587
|
-
});
|
|
624
|
+
});
|
|
588
625
|
}
|
|
589
626
|
|
|
627
|
+
define.classMethod('unlink', {callback: true, promise:true});
|
|
628
|
+
|
|
590
629
|
/**
|
|
591
630
|
* Retrieves the file collection associated with this object.
|
|
592
631
|
*
|
|
593
632
|
* @method
|
|
594
633
|
* @param {GridStore~collectionCallback} callback the command callback.
|
|
595
634
|
* @return {Collection}
|
|
635
|
+
* @deprecated Use GridFSBucket API instead
|
|
596
636
|
*/
|
|
597
637
|
GridStore.prototype.collection = function(callback) {
|
|
598
638
|
if(typeof callback == 'function')
|
|
@@ -600,6 +640,8 @@ GridStore.prototype.collection = function(callback) {
|
|
|
600
640
|
return this.db.collection(this.root + ".files");
|
|
601
641
|
};
|
|
602
642
|
|
|
643
|
+
define.classMethod('collection', {callback: true, promise:false, returns: [Collection]});
|
|
644
|
+
|
|
603
645
|
/**
|
|
604
646
|
* The readlines callback format.
|
|
605
647
|
* @callback GridStore~readlinesCallback
|
|
@@ -612,8 +654,9 @@ GridStore.prototype.collection = function(callback) {
|
|
|
612
654
|
*
|
|
613
655
|
* @method
|
|
614
656
|
* @param {string} [separator] The character to be recognized as the newline separator.
|
|
615
|
-
* @param {GridStore~readlinesCallback} callback the command callback.
|
|
657
|
+
* @param {GridStore~readlinesCallback} [callback] the command callback.
|
|
616
658
|
* @return {Promise} returns Promise if no callback passed
|
|
659
|
+
* @deprecated Use GridFSBucket API instead
|
|
617
660
|
*/
|
|
618
661
|
GridStore.prototype.readlines = function(separator, callback) {
|
|
619
662
|
var self = this;
|
|
@@ -622,7 +665,7 @@ GridStore.prototype.readlines = function(separator, callback) {
|
|
|
622
665
|
if(typeof callback != 'function') args.push(callback);
|
|
623
666
|
separator = args.length ? args.shift() : "\n";
|
|
624
667
|
separator = separator || "\n";
|
|
625
|
-
|
|
668
|
+
|
|
626
669
|
// We provided a callback leg
|
|
627
670
|
if(typeof callback == 'function') return readlines(self, separator, callback);
|
|
628
671
|
|
|
@@ -646,16 +689,19 @@ var readlines = function(self, separator, callback) {
|
|
|
646
689
|
}
|
|
647
690
|
|
|
648
691
|
callback(null, items);
|
|
649
|
-
});
|
|
692
|
+
});
|
|
650
693
|
}
|
|
651
694
|
|
|
695
|
+
define.classMethod('readlines', {callback: true, promise:true});
|
|
696
|
+
|
|
652
697
|
/**
|
|
653
698
|
* Deletes all the chunks of this file in the database if mode was set to "w" or
|
|
654
699
|
* "w+" and resets the read/write head to the initial position.
|
|
655
700
|
*
|
|
656
701
|
* @method
|
|
657
|
-
* @param {GridStore~resultCallback} callback this will be called after executing this method. The first parameter will contain null and the second one will contain a reference to this object.
|
|
702
|
+
* @param {GridStore~resultCallback} [callback] this will be called after executing this method. The first parameter will contain null and the second one will contain a reference to this object.
|
|
658
703
|
* @return {Promise} returns Promise if no callback passed
|
|
704
|
+
* @deprecated Use GridFSBucket API instead
|
|
659
705
|
*/
|
|
660
706
|
GridStore.prototype.rewind = function(callback) {
|
|
661
707
|
var self = this;
|
|
@@ -692,9 +738,11 @@ var rewind = function(self, callback) {
|
|
|
692
738
|
self.currentChunk.rewind();
|
|
693
739
|
self.position = 0;
|
|
694
740
|
callback(null, self);
|
|
695
|
-
}
|
|
741
|
+
}
|
|
696
742
|
}
|
|
697
743
|
|
|
744
|
+
define.classMethod('rewind', {callback: true, promise:true});
|
|
745
|
+
|
|
698
746
|
/**
|
|
699
747
|
* The read callback format.
|
|
700
748
|
* @callback GridStore~readCallback
|
|
@@ -714,8 +762,9 @@ var rewind = function(self, callback) {
|
|
|
714
762
|
* @method
|
|
715
763
|
* @param {number} [length] the number of characters to read. Reads all the characters from the read/write head to the EOF if not specified.
|
|
716
764
|
* @param {(string|Buffer)} [buffer] a string to hold temporary data. This is used for storing the string data read so far when recursively calling this method.
|
|
717
|
-
* @param {GridStore~readCallback} callback the command callback.
|
|
765
|
+
* @param {GridStore~readCallback} [callback] the command callback.
|
|
718
766
|
* @return {Promise} returns Promise if no callback passed
|
|
767
|
+
* @deprecated Use GridFSBucket API instead
|
|
719
768
|
*/
|
|
720
769
|
GridStore.prototype.read = function(length, buffer, callback) {
|
|
721
770
|
var self = this;
|
|
@@ -750,7 +799,7 @@ var read = function(self, length, buffer, callback) {
|
|
|
750
799
|
// Update internal position
|
|
751
800
|
self.position = self.position + finalBuffer.length;
|
|
752
801
|
// Check if we don't have a file at all
|
|
753
|
-
if(finalLength == 0 && finalBuffer.length == 0) return callback(
|
|
802
|
+
if(finalLength == 0 && finalBuffer.length == 0) return callback(MongoError.create({message: "File does not exist", driver:true}), null);
|
|
754
803
|
// Else return data
|
|
755
804
|
return callback(null, finalBuffer);
|
|
756
805
|
}
|
|
@@ -773,12 +822,14 @@ var read = function(self, length, buffer, callback) {
|
|
|
773
822
|
if(finalBuffer._index > 0) {
|
|
774
823
|
callback(null, finalBuffer)
|
|
775
824
|
} else {
|
|
776
|
-
callback(
|
|
825
|
+
callback(MongoError.create({message: "no chunks found for file, possibly corrupt", driver:true}), null);
|
|
777
826
|
}
|
|
778
827
|
}
|
|
779
|
-
});
|
|
828
|
+
});
|
|
780
829
|
}
|
|
781
830
|
|
|
831
|
+
define.classMethod('read', {callback: true, promise:true});
|
|
832
|
+
|
|
782
833
|
/**
|
|
783
834
|
* The tell callback format.
|
|
784
835
|
* @callback GridStore~tellCallback
|
|
@@ -792,8 +843,9 @@ var read = function(self, length, buffer, callback) {
|
|
|
792
843
|
* @method
|
|
793
844
|
* @param {number} [length] the number of characters to read. Reads all the characters from the read/write head to the EOF if not specified.
|
|
794
845
|
* @param {(string|Buffer)} [buffer] a string to hold temporary data. This is used for storing the string data read so far when recursively calling this method.
|
|
795
|
-
* @param {GridStore~tellCallback} callback the command callback.
|
|
846
|
+
* @param {GridStore~tellCallback} [callback] the command callback.
|
|
796
847
|
* @return {Promise} returns Promise if no callback passed
|
|
848
|
+
* @deprecated Use GridFSBucket API instead
|
|
797
849
|
*/
|
|
798
850
|
GridStore.prototype.tell = function(callback) {
|
|
799
851
|
var self = this;
|
|
@@ -805,6 +857,8 @@ GridStore.prototype.tell = function(callback) {
|
|
|
805
857
|
});
|
|
806
858
|
};
|
|
807
859
|
|
|
860
|
+
define.classMethod('tell', {callback: true, promise:true});
|
|
861
|
+
|
|
808
862
|
/**
|
|
809
863
|
* The tell callback format.
|
|
810
864
|
* @callback GridStore~gridStoreCallback
|
|
@@ -825,8 +879,9 @@ GridStore.prototype.tell = function(callback) {
|
|
|
825
879
|
* @method
|
|
826
880
|
* @param {number} [position] the position to seek to
|
|
827
881
|
* @param {number} [seekLocation] seek mode. Use one of the Seek Location modes.
|
|
828
|
-
* @param {GridStore~gridStoreCallback} callback the command callback.
|
|
882
|
+
* @param {GridStore~gridStoreCallback} [callback] the command callback.
|
|
829
883
|
* @return {Promise} returns Promise if no callback passed
|
|
884
|
+
* @deprecated Use GridFSBucket API instead
|
|
830
885
|
*/
|
|
831
886
|
GridStore.prototype.seek = function(position, seekLocation, callback) {
|
|
832
887
|
var self = this;
|
|
@@ -850,7 +905,7 @@ GridStore.prototype.seek = function(position, seekLocation, callback) {
|
|
|
850
905
|
var seek = function(self, position, seekLocation, callback) {
|
|
851
906
|
// Seek only supports read mode
|
|
852
907
|
if(self.mode != 'r') {
|
|
853
|
-
return callback(
|
|
908
|
+
return callback(MongoError.create({message: "seek is only supported for mode r", driver:true}))
|
|
854
909
|
}
|
|
855
910
|
|
|
856
911
|
var seekLocationFinal = seekLocation == null ? GridStore.IO_SEEK_SET : seekLocation;
|
|
@@ -870,6 +925,10 @@ var seek = function(self, position, seekLocation, callback) {
|
|
|
870
925
|
var newChunkNumber = Math.floor(targetPosition/self.chunkSize);
|
|
871
926
|
var seekChunk = function() {
|
|
872
927
|
nthChunk(self, newChunkNumber, function(err, chunk) {
|
|
928
|
+
if(err) return callback(err, null);
|
|
929
|
+
if(chunk == null) return callback(new Error('no chunk found'));
|
|
930
|
+
|
|
931
|
+
// Set the current chunk
|
|
873
932
|
self.currentChunk = chunk;
|
|
874
933
|
self.position = targetPosition;
|
|
875
934
|
self.currentChunk.position = (self.position % self.chunkSize);
|
|
@@ -877,9 +936,11 @@ var seek = function(self, position, seekLocation, callback) {
|
|
|
877
936
|
});
|
|
878
937
|
};
|
|
879
938
|
|
|
880
|
-
seekChunk();
|
|
939
|
+
seekChunk();
|
|
881
940
|
}
|
|
882
941
|
|
|
942
|
+
define.classMethod('seek', {callback: true, promise:true});
|
|
943
|
+
|
|
883
944
|
/**
|
|
884
945
|
* @ignore
|
|
885
946
|
*/
|
|
@@ -913,9 +974,9 @@ var _open = function(self, options, callback) {
|
|
|
913
974
|
self.internalChunkSize = self.internalChunkSize == null ? Chunk.DEFAULT_CHUNK_SIZE : self.internalChunkSize;
|
|
914
975
|
self.length = 0;
|
|
915
976
|
} else {
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
977
|
+
self.length = 0;
|
|
978
|
+
var txtId = self.fileId instanceof ObjectID ? self.fileId.toHexString() : self.fileId;
|
|
979
|
+
return error(MongoError.create({message: f("file with id %s not opened for writing", (self.referenceBy == REFERENCE_BY_ID ? txtId : self.filename)), driver:true}), self);
|
|
919
980
|
}
|
|
920
981
|
|
|
921
982
|
// Process the mode of the object
|
|
@@ -926,7 +987,7 @@ var _open = function(self, options, callback) {
|
|
|
926
987
|
self.position = 0;
|
|
927
988
|
callback(null, self);
|
|
928
989
|
});
|
|
929
|
-
} else if(self.mode == "w") {
|
|
990
|
+
} else if(self.mode == "w" && doc) {
|
|
930
991
|
// Delete any existing chunks
|
|
931
992
|
deleteChunks(self, options, function(err, result) {
|
|
932
993
|
if(err) return error(err);
|
|
@@ -938,6 +999,14 @@ var _open = function(self, options, callback) {
|
|
|
938
999
|
self.position = 0;
|
|
939
1000
|
callback(null, self);
|
|
940
1001
|
});
|
|
1002
|
+
} else if(self.mode == "w") {
|
|
1003
|
+
self.currentChunk = new Chunk(self, {'n':0}, self.writeConcern);
|
|
1004
|
+
self.contentType = self.options['content_type'] == null ? self.contentType : self.options['content_type'];
|
|
1005
|
+
self.internalChunkSize = self.options['chunk_size'] == null ? self.internalChunkSize : self.options['chunk_size'];
|
|
1006
|
+
self.metadata = self.options['metadata'] == null ? self.metadata : self.options['metadata'];
|
|
1007
|
+
self.aliases = self.options['aliases'] == null ? self.aliases : self.options['aliases'];
|
|
1008
|
+
self.position = 0;
|
|
1009
|
+
callback(null, self);
|
|
941
1010
|
} else if(self.mode == "w+") {
|
|
942
1011
|
nthChunk(self, lastChunkNumber(self), options, function(err, chunk) {
|
|
943
1012
|
if(err) return error(err);
|
|
@@ -1001,7 +1070,7 @@ var writeBuffer = function(self, buffer, close, callback) {
|
|
|
1001
1070
|
var finalClose = typeof close == 'boolean' ? close : false;
|
|
1002
1071
|
|
|
1003
1072
|
if(self.mode != "w") {
|
|
1004
|
-
callback(
|
|
1073
|
+
callback(MongoError.create({message: f("file with id %s not opened for writing", (self.referenceBy == REFERENCE_BY_ID ? self.referenceBy : self.filename)), driver:true}), null);
|
|
1005
1074
|
} else {
|
|
1006
1075
|
if(self.currentChunk.position + buffer.length >= self.chunkSize) {
|
|
1007
1076
|
// Write out the current Chunk and then keep writing until we have less data left than a chunkSize left
|
|
@@ -1209,8 +1278,9 @@ GridStore.IO_SEEK_END = 2;
|
|
|
1209
1278
|
* @param {object} [options=null] Optional settings.
|
|
1210
1279
|
* @param {(ReadPreference|string)} [options.readPreference=null] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
|
|
1211
1280
|
* @param {object} [options.promiseLibrary=null] A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
|
|
1212
|
-
* @param {GridStore~resultCallback} callback result from exists.
|
|
1281
|
+
* @param {GridStore~resultCallback} [callback] result from exists.
|
|
1213
1282
|
* @return {Promise} returns Promise if no callback passed
|
|
1283
|
+
* @deprecated Use GridFSBucket API instead
|
|
1214
1284
|
*/
|
|
1215
1285
|
GridStore.exist = function(db, fileIdObject, rootCollection, options, callback) {
|
|
1216
1286
|
var args = Array.prototype.slice.call(arguments, 2);
|
|
@@ -1254,8 +1324,8 @@ var exists = function(db, fileIdObject, rootCollection, options, callback) {
|
|
|
1254
1324
|
: {'_id':fileIdObject}; // Attempt to locate file
|
|
1255
1325
|
|
|
1256
1326
|
// We have a specific query
|
|
1257
|
-
if(fileIdObject != null
|
|
1258
|
-
&& typeof fileIdObject == 'object'
|
|
1327
|
+
if(fileIdObject != null
|
|
1328
|
+
&& typeof fileIdObject == 'object'
|
|
1259
1329
|
&& Object.prototype.toString.call(fileIdObject) != '[object RegExp]') {
|
|
1260
1330
|
query = fileIdObject;
|
|
1261
1331
|
}
|
|
@@ -1265,9 +1335,11 @@ var exists = function(db, fileIdObject, rootCollection, options, callback) {
|
|
|
1265
1335
|
if(err) return callback(err);
|
|
1266
1336
|
callback(null, item == null ? false : true);
|
|
1267
1337
|
});
|
|
1268
|
-
});
|
|
1338
|
+
});
|
|
1269
1339
|
}
|
|
1270
1340
|
|
|
1341
|
+
define.staticMethod('exist', {callback: true, promise:true});
|
|
1342
|
+
|
|
1271
1343
|
/**
|
|
1272
1344
|
* Gets the list of files stored in the GridFS.
|
|
1273
1345
|
*
|
|
@@ -1278,8 +1350,9 @@ var exists = function(db, fileIdObject, rootCollection, options, callback) {
|
|
|
1278
1350
|
* @param {object} [options=null] Optional settings.
|
|
1279
1351
|
* @param {(ReadPreference|string)} [options.readPreference=null] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
|
|
1280
1352
|
* @param {object} [options.promiseLibrary=null] A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
|
|
1281
|
-
* @param {GridStore~resultCallback} callback result from exists.
|
|
1353
|
+
* @param {GridStore~resultCallback} [callback] result from exists.
|
|
1282
1354
|
* @return {Promise} returns Promise if no callback passed
|
|
1355
|
+
* @deprecated Use GridFSBucket API instead
|
|
1283
1356
|
*/
|
|
1284
1357
|
GridStore.list = function(db, rootCollection, options, callback) {
|
|
1285
1358
|
var args = Array.prototype.slice.call(arguments, 1);
|
|
@@ -1337,9 +1410,11 @@ var list = function(db, rootCollection, options, callback) {
|
|
|
1337
1410
|
}
|
|
1338
1411
|
});
|
|
1339
1412
|
});
|
|
1340
|
-
});
|
|
1413
|
+
});
|
|
1341
1414
|
}
|
|
1342
1415
|
|
|
1416
|
+
define.staticMethod('list', {callback: true, promise:true});
|
|
1417
|
+
|
|
1343
1418
|
/**
|
|
1344
1419
|
* Reads the contents of a file.
|
|
1345
1420
|
*
|
|
@@ -1359,10 +1434,10 @@ var list = function(db, rootCollection, options, callback) {
|
|
|
1359
1434
|
* @param {object} [options=null] Optional settings.
|
|
1360
1435
|
* @param {(ReadPreference|string)} [options.readPreference=null] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
|
|
1361
1436
|
* @param {object} [options.promiseLibrary=null] A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
|
|
1362
|
-
* @param {GridStore~readCallback} callback the command callback.
|
|
1437
|
+
* @param {GridStore~readCallback} [callback] the command callback.
|
|
1363
1438
|
* @return {Promise} returns Promise if no callback passed
|
|
1439
|
+
* @deprecated Use GridFSBucket API instead
|
|
1364
1440
|
*/
|
|
1365
|
-
|
|
1366
1441
|
GridStore.read = function(db, name, length, offset, options, callback) {
|
|
1367
1442
|
var args = Array.prototype.slice.call(arguments, 2);
|
|
1368
1443
|
callback = args.pop();
|
|
@@ -1408,9 +1483,11 @@ var readStatic = function(db, name, length, offset, options, callback) {
|
|
|
1408
1483
|
} else {
|
|
1409
1484
|
gridStore.read(length, callback);
|
|
1410
1485
|
}
|
|
1411
|
-
});
|
|
1486
|
+
});
|
|
1412
1487
|
}
|
|
1413
1488
|
|
|
1489
|
+
define.staticMethod('read', {callback: true, promise:true});
|
|
1490
|
+
|
|
1414
1491
|
/**
|
|
1415
1492
|
* Read the entire file as a list of strings splitting by the provided separator.
|
|
1416
1493
|
*
|
|
@@ -1422,8 +1499,9 @@ var readStatic = function(db, name, length, offset, options, callback) {
|
|
|
1422
1499
|
* @param {object} [options=null] Optional settings.
|
|
1423
1500
|
* @param {(ReadPreference|string)} [options.readPreference=null] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
|
|
1424
1501
|
* @param {object} [options.promiseLibrary=null] A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
|
|
1425
|
-
* @param {GridStore~readlinesCallback} callback the command callback.
|
|
1502
|
+
* @param {GridStore~readlinesCallback} [callback] the command callback.
|
|
1426
1503
|
* @return {Promise} returns Promise if no callback passed
|
|
1504
|
+
* @deprecated Use GridFSBucket API instead
|
|
1427
1505
|
*/
|
|
1428
1506
|
GridStore.readlines = function(db, name, separator, options, callback) {
|
|
1429
1507
|
var args = Array.prototype.slice.call(arguments, 2);
|
|
@@ -1458,9 +1536,11 @@ var readlinesStatic = function(db, name, separator, options, callback) {
|
|
|
1458
1536
|
new GridStore(db, name, "r", options).open(function(err, gridStore) {
|
|
1459
1537
|
if(err) return callback(err);
|
|
1460
1538
|
gridStore.readlines(finalSeperator, callback);
|
|
1461
|
-
});
|
|
1539
|
+
});
|
|
1462
1540
|
}
|
|
1463
1541
|
|
|
1542
|
+
define.staticMethod('readlines', {callback: true, promise:true});
|
|
1543
|
+
|
|
1464
1544
|
/**
|
|
1465
1545
|
* Deletes the chunks and metadata information of a file from GridFS.
|
|
1466
1546
|
*
|
|
@@ -1470,8 +1550,9 @@ var readlinesStatic = function(db, name, separator, options, callback) {
|
|
|
1470
1550
|
* @param {(string|array)} names The name/names of the files to delete.
|
|
1471
1551
|
* @param {object} [options=null] Optional settings.
|
|
1472
1552
|
* @param {object} [options.promiseLibrary=null] A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
|
|
1473
|
-
* @param {GridStore~resultCallback} callback the command callback.
|
|
1553
|
+
* @param {GridStore~resultCallback} [callback] the command callback.
|
|
1474
1554
|
* @return {Promise} returns Promise if no callback passed
|
|
1555
|
+
* @deprecated Use GridFSBucket API instead
|
|
1475
1556
|
*/
|
|
1476
1557
|
GridStore.unlink = function(db, names, options, callback) {
|
|
1477
1558
|
var self = this;
|
|
@@ -1530,9 +1611,11 @@ var unlinkStatic = function(self, db, names, options, callback) {
|
|
|
1530
1611
|
});
|
|
1531
1612
|
});
|
|
1532
1613
|
});
|
|
1533
|
-
}
|
|
1614
|
+
}
|
|
1534
1615
|
}
|
|
1535
1616
|
|
|
1617
|
+
define.staticMethod('unlink', {callback: true, promise:true});
|
|
1618
|
+
|
|
1536
1619
|
/**
|
|
1537
1620
|
* @ignore
|
|
1538
1621
|
*/
|
|
@@ -1583,7 +1666,7 @@ var _getWriteConcern = function(self, options) {
|
|
|
1583
1666
|
|
|
1584
1667
|
// Ensure we don't have an invalid combination of write concerns
|
|
1585
1668
|
if(finalOptions.w < 1
|
|
1586
|
-
&& (finalOptions.journal == true || finalOptions.j == true || finalOptions.fsync == true)) throw
|
|
1669
|
+
&& (finalOptions.journal == true || finalOptions.j == true || finalOptions.fsync == true)) throw MongoError.create({message: "No acknowledgement using w < 1 cannot be combined with journal:true or fsync:true", driver:true});
|
|
1587
1670
|
|
|
1588
1671
|
// Return the options
|
|
1589
1672
|
return finalOptions;
|
|
@@ -1595,6 +1678,7 @@ var _getWriteConcern = function(self, options) {
|
|
|
1595
1678
|
* @class
|
|
1596
1679
|
* @extends external:Duplex
|
|
1597
1680
|
* @return {GridStoreStream} a GridStoreStream instance.
|
|
1681
|
+
* @deprecated Use GridFSBucket API instead
|
|
1598
1682
|
*/
|
|
1599
1683
|
var GridStoreStream = function(gs) {
|
|
1600
1684
|
var self = this;
|
|
@@ -1631,8 +1715,10 @@ GridStoreStream.prototype.pipe = function(destination) {
|
|
|
1631
1715
|
});
|
|
1632
1716
|
} else {
|
|
1633
1717
|
self.totalBytesToRead = self.gs.length - self.gs.position;
|
|
1634
|
-
self._pipe.apply(self, [destination]);
|
|
1718
|
+
self._pipe.apply(self, [destination]);
|
|
1635
1719
|
}
|
|
1720
|
+
|
|
1721
|
+
return destination;
|
|
1636
1722
|
}
|
|
1637
1723
|
|
|
1638
1724
|
// Called by stream
|
|
@@ -1659,7 +1745,7 @@ GridStoreStream.prototype._read = function(n) {
|
|
|
1659
1745
|
if(self.totalBytesToRead <= 0) {
|
|
1660
1746
|
self.endCalled = true;
|
|
1661
1747
|
}
|
|
1662
|
-
});
|
|
1748
|
+
});
|
|
1663
1749
|
}
|
|
1664
1750
|
|
|
1665
1751
|
// Set read length
|
|
@@ -1684,7 +1770,7 @@ GridStoreStream.prototype.destroy = function() {
|
|
|
1684
1770
|
|
|
1685
1771
|
GridStoreStream.prototype.write = function(chunk, encoding, callback) {
|
|
1686
1772
|
var self = this;
|
|
1687
|
-
if(self.endCalled) return self.emit('error',
|
|
1773
|
+
if(self.endCalled) return self.emit('error', MongoError.create({message: 'attempting to write to stream after end called', driver:true}))
|
|
1688
1774
|
// Do we have to open the gridstore
|
|
1689
1775
|
if(!self.gs.isOpen) {
|
|
1690
1776
|
self.gs.open(function() {
|