Skip to content

Commit

Permalink
Fixing problems with collection names which have the same name as fun…
Browse files Browse the repository at this point in the history
…ctions in native

If you have collection names which are identical to functions in the mongodb-native you will get in trouble with the changes on the db prototype (a37030a and 26d17aa).
This small fix changes the behaviour:
If you initialize collection names with the connect they will overwrite the prototype functions.
If you use the explicit collection() you will always get the collection and not the possible available prototype function.
  • Loading branch information
Osterjour committed Jul 25, 2013
1 parent ac10c44 commit 3567157
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ Database.prototype.runCommand = function(opts, callback) {

Database.prototype.collection = function(name) {
var self = this;
if (this[name]) return this[name];

var oncollection = thunky(function(callback) {
self._get(function(err, db) {
Expand All @@ -251,7 +250,7 @@ Database.prototype.collection = function(name) {
});
});

return this[name] = new Collection(oncollection);
return new Collection(oncollection);
};

forEachMethod(DRIVER_DB_PROTO, Database.prototype, function(methodName, fn) {
Expand Down Expand Up @@ -282,7 +281,7 @@ var connect = function(config, collections) {

collections = collections || config.collections || [];
collections.forEach(function(colName) {
that.collection(colName);
that[colName] = that.collection(colName);
});

return that;
Expand Down

0 comments on commit 3567157

Please sign in to comment.