Skip to content

Commit

Permalink
feat(Collection): warn if callback is not function in find and findOne
Browse files Browse the repository at this point in the history
  • Loading branch information
daprahamian committed Jun 26, 2018
1 parent 36c591d commit cddaba0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ const DEPRECATED_FIND_OPTIONS = ['maxScan', 'snapshot'];
* @return {Cursor}
*/
Collection.prototype.find = function(query, options, callback) {
if (typeof callback === 'object') {
// TODO(MAJOR): throw in the future
console.warn('Third parameter to `find()` must be a callback or undefined');
}

let selector = query;
// figuring out arguments
if (typeof callback !== 'function') {
Expand Down Expand Up @@ -1003,6 +1008,11 @@ Collection.prototype.save = function(doc, options, callback) {
* @return {Promise} returns Promise if no callback passed
*/
Collection.prototype.findOne = function(query, options, callback) {
if (typeof callback === 'object') {
// TODO(MAJOR): throw in the future
console.warn('Third parameter to `findOne()` must be a callback or undefined');
}

if (typeof query === 'function') (callback = query), (query = {}), (options = {});
if (typeof options === 'function') (callback = options), (options = {});
query = query || {};
Expand Down

0 comments on commit cddaba0

Please sign in to comment.