Skip to content

Commit

Permalink
Alias find as findById
Browse files Browse the repository at this point in the history
  • Loading branch information
jannyHou committed Jan 11, 2018
1 parent 42025d5 commit 0f9b573
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,9 @@ MongoDB.prototype.find = function find(model, id, options, callback) {
});
};

Connector.defineAliases(MongoDB.prototype, 'find',
'findById');

/**
* Parses the data input for update operations and returns the
* sanitised version of the object.
Expand Down
31 changes: 31 additions & 0 deletions test/connector-functions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright IBM Corp. 2013,2016. All Rights Reserved.
// Node module: loopback-connector-mongodb
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

// This test written in mocha+should.js
var should = require('./init.js');

describe('connector function - findById', function() {
var db, TestAlias, sampleId;
before(function(done) {
db = getDataSource();
TestAlias = db.define('TestAlias', { foo: { type: String }});
db.automigrate(function(err) {
if (err) return done(err);
TestAlias.create({ foo: 'foo' }, function(err, t) {
if (err) return done(err);
sampleId = t.id;
done();
});
});
});

it('find is aliased as findById', function(done) {
db.connector.findById('TestAlias', sampleId, {}, function(err, r) {
if (err) return done(err);
r.foo.should.equal('foo');
done();
});
});
});

0 comments on commit 0f9b573

Please sign in to comment.