Skip to content

Commit e80d98d

Browse files
committed
Issue #272 and #265
1 parent 6aaaede commit e80d98d

File tree

7 files changed

+67
-17
lines changed

7 files changed

+67
-17
lines changed

HISTORY

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
0.9.6-5 2011-07-06
2+
* Rewritten BSON js parser now faster than the C parser on my core2duo laptop
3+
* Added option full to indexInformation to get all index info Issue #265
4+
* Passing in ObjectID for new Gridstore works correctly Issue #272
5+
16
0.9.6-4 2011-07-01
27
* Added test and bug fix for insert/update/remove without callback supplied
38

lib/mongodb/collection.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -769,11 +769,17 @@ Collection.prototype.ensureIndex = function ensureIndex (fieldOrSpec, options, c
769769
/**
770770
* Retrieves this collections index info.
771771
*
772+
* @param {Object} options -
773+
* full: {Bool} set to true to remove raw index information
772774
* @param {Function} callback
773775
*/
774-
775-
Collection.prototype.indexInformation = function indexInformation (callback) {
776-
this.db.indexInformation(this.collectionName, callback);
776+
Collection.prototype.indexInformation = function indexInformation (options, callback) {
777+
// Unpack calls
778+
var args = Array.prototype.slice.call(arguments, 0);
779+
callback = args.pop();
780+
options = args.length ? args.shift() : {};
781+
// Call the index information
782+
this.db.indexInformation(this.collectionName, options, callback);
777783
};
778784

779785
/**

lib/mongodb/db.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -526,24 +526,38 @@ Db.prototype.dropIndex = function(collectionName, indexName, callback) {
526526
/**
527527
Index Information
528528
**/
529-
Db.prototype.indexInformation = function(collectionName, callback) {
530-
if(typeof collectionName === "function") { callback = collectionName; collectionName = null;}
529+
Db.prototype.indexInformation = function(collectionName, options, callback) {
530+
// Unpack calls
531+
var args = Array.prototype.slice.call(arguments, 0);
532+
callback = args.pop();
533+
collectionName = args.length ? args.shift() : null;
534+
options = args.length ? args.shift() : {};
535+
536+
// If we specified full information
537+
var full = options['full'] == null ? false : options['full'];
531538
// Build selector for the indexes
532539
var selector = collectionName != null ? {ns: (this.databaseName + "." + collectionName)} : {};
533-
var info = {};
534540
// Iterate through all the fields of the index
535-
new Cursor(this, new Collection(this, DbCommand.SYSTEM_INDEX_COLLECTION), selector).each(function(err, index) {
541+
new Cursor(this, new Collection(this, DbCommand.SYSTEM_INDEX_COLLECTION), selector).toArray(function(err, indexes) {
536542
if(err != null) return callback(err, null);
543+
// Contains all the information
544+
var info = {};
537545

538-
// Return the info when finished
539-
if(index == null) {
540-
callback(null, info);
541-
} else {
546+
// if full defined just return all the indexes directly
547+
if(full) return callback(null, indexes);
548+
549+
// Process all the indexes
550+
for(var i = 0; i < indexes.length; i++) {
551+
var index = indexes[i];
552+
// Let's unpack the object
542553
info[index.name] = [];
543554
for(var name in index.key) {
544555
info[index.name].push([name, index.key[name]]);
545556
}
546557
}
558+
559+
// Return all the indexes
560+
callback(null, info);
547561
});
548562
};
549563

lib/mongodb/gridfs/gridstore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ GridStore.prototype._open = function(callback) {
154154
self.metadata = doc.metadata;
155155
self.internalMd5 = doc.md5;
156156
} else {
157-
self.fileId = new self.db.bson_serializer.ObjectID();
157+
self.fileId = self.fileId instanceof self.db.bson_serializer.ObjectID ? self.fileId : new self.db.bson_serializer.ObjectID();
158158
self.contentType = exports.GridStore.DEFAULT_CONTENT_TYPE;
159159
self.internalChunkSize = self.internalChunkSize == null ? Chunk.DEFAULT_CHUNK_SIZE : self.internalChunkSize;
160160
self.length = 0;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{ "name" : "mongodb"
22
, "description" : "A node.js driver for MongoDB"
3-
, "version" : "0.9.6-4"
3+
, "version" : "0.9.6-5"
44
, "author" : "Christian Amor Kvalheim <christkv@gmail.com>"
55
, "contributors" : [ "Nathan White <nw@nwhite.net>",
66
"Adam Wiggins <adam@heroku.com>",

test/gridstore/grid_store_test.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,19 +619,39 @@ var tests = testCase({
619619
// Write the file using writeBuffer
620620
gridStore.writeBuffer(data, function(err, doc) {
621621
gridStore.close(function(err, doc) {
622-
622+
623623
// Read the file using readBuffer
624624
GridStore.exist(client, doc._id, function(err, result) {
625625
test.equal(null, err);
626626
test.equal(true, result);
627-
627+
628628
client.close();
629629
test.done();
630630
});
631631
});
632632
})
633633
});
634634
},
635+
636+
shouldCorrectlySaveDataByObjectID : function(test) {
637+
var id = new client.bson_serializer.ObjectID();
638+
var gridStore = new GridStore(client, id, 'w');
639+
640+
gridStore.open(function(err, gridStore) {
641+
gridStore.write('bar', function(err, gridStore) {
642+
gridStore.close(function(err, result) {
643+
644+
GridStore.exist(client, id, function(err, result) {
645+
test.equal(null, err);
646+
test.equal(true, result);
647+
648+
client.close();
649+
test.done();
650+
});
651+
});
652+
});
653+
});
654+
}
635655
})
636656

637657
// Stupid freaking workaround due to there being no way to run setup once for each suite

test/index_test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ var tests = testCase({
139139
client.error(function(err, errors) {
140140
test.equal(1, errors.length);
141141
test.ok(errors[0].err == null);
142-
142+
143143
// Create a unique subfield index and test that insert fails
144144
client.createCollection('test_index_on_subfield2', function(err, collection) {
145145
client.createIndex(collection.collectionName, 'hello.a', true, function(err, indexName) {
@@ -232,7 +232,12 @@ var tests = testCase({
232232
test.equal(1, items.length);
233233
test.equal("Sarah", items[0].name);
234234

235-
test.done();
235+
// Fetch the info for the indexes
236+
collection.indexInformation({full:true}, function(err, indexInfo) {
237+
test.equal(null, err);
238+
test.equal(2, indexInfo.length);
239+
test.done();
240+
})
236241
})
237242
});
238243
})

0 commit comments

Comments
 (0)