Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// make sure we don't send in the whole Document to merge()
if (conditions instanceof Document) {
conditions = conditions.toObject();
}
if (options) {
this.setOptions(options);
}
if (fields) {
this.select(fields);
}
if (mquery.canMerge(conditions)) {
this.merge(conditions);
}
prepareDiscriminatorCriteria(this);
try {
this.cast(this.model);
this._castError = null;
} catch (err) {
this._castError = err;
}
if (!callback) {
// already merged in the conditions, don't need to send them in.
return Query.base.findOne.call(this);
}
Query.prototype.find = function(conditions, callback) {
if (typeof conditions === 'function') {
callback = conditions;
conditions = {};
}
conditions = utils.toObject(conditions);
if (mquery.canMerge(conditions)) {
this.merge(conditions);
prepareDiscriminatorCriteria(this);
} else if (conditions != null) {
this.error(new ObjectParameterError(conditions, 'filter', 'find'));
}
// if we don't have a callback, then just return the query object
if (!callback) {
return Query.base.find.call(this);
}
this._find(callback);
return this;
};
}
// make sure we don't send in the whole Document to merge()
if (conditions instanceof Document) {
conditions = conditions.toObject();
}
if (options) {
this.setOptions(options);
}
if (fields) {
this.select(fields);
}
if (mquery.canMerge(conditions)) {
this.merge(conditions);
}
prepareDiscriminatorCriteria(this);
try {
this.cast(this.model);
this._castError = null;
} catch (err) {
this._castError = err;
}
if (!callback) {
// already merged in the conditions, don't need to send them in.
return Query.base.findOne.call(this);
}
}
// make sure we don't send in the whole Document to merge()
if (conditions instanceof Document) {
conditions = conditions.toObject();
}
if (options) {
this.setOptions(options);
}
if (fields) {
this.select(fields);
}
if (mquery.canMerge(conditions)) {
this.merge(conditions);
}
prepareDiscriminatorCriteria(this);
try {
this.cast(this.model);
this._castError = null;
} catch (err) {
this._castError = err;
}
if (!callback) {
// already merged in the conditions, don't need to send them in.
return Query.base.findOne.call(this);
}
Query.prototype.find = function (conditions, callback) {
if ('function' == typeof conditions) {
callback = conditions;
conditions = {};
} else if (conditions instanceof Document) {
conditions = conditions.toObject();
}
if (mquery.canMerge(conditions)) {
this.merge(conditions);
}
prepareDiscriminatorCriteria(this);
try {
this.cast(this.model);
this._castError = null;
} catch (err) {
this._castError = err;
}
// if we don't have a callback, then just return the query object
if (!callback) {
return Query.base.find.call(this);
}
Query.prototype.deleteOne = function(filter, callback) {
if (typeof filter === 'function') {
callback = filter;
filter = null;
}
filter = utils.toObject(filter);
if (mquery.canMerge(filter)) {
this.merge(filter);
prepareDiscriminatorCriteria(this);
} else if (filter != null) {
this.error(new ObjectParameterError(filter, 'filter', 'deleteOne'));
}
if (!callback) {
return Query.base.deleteOne.call(this);
}
this._deleteOne.call(this, callback);
return this;
};
Query.prototype.deleteMany = function(filter, callback) {
if (typeof filter === 'function') {
callback = filter;
filter = null;
}
filter = utils.toObject(filter);
if (mquery.canMerge(filter)) {
this.merge(filter);
prepareDiscriminatorCriteria(this);
} else if (filter != null) {
this.error(new ObjectParameterError(filter, 'filter', 'deleteMany'));
}
if (!callback) {
return Query.base.deleteMany.call(this);
}
return this._deleteMany.call(this, callback);
};
Query.prototype.count = function (conditions, callback) {
if ('function' == typeof conditions) {
callback = conditions;
conditions = undefined;
}
if (mquery.canMerge(conditions)) {
this.merge(conditions);
}
this.op = 'count';
if (!callback) {
return this;
}
this._count(callback);
return this;
}
Query.prototype.count = function (conditions, callback) {
if ('function' == typeof conditions) {
callback = conditions;
conditions = undefined;
}
if (mquery.canMerge(conditions)) {
this.merge(conditions);
}
try {
this.cast(this.model);
} catch (err) {
callback(err);
return this;
}
return Query.base.count.call(this, {}, callback);
}
Query.prototype.count = function(conditions, callback) {
if (typeof conditions === 'function') {
callback = conditions;
conditions = undefined;
}
if (mquery.canMerge(conditions)) {
this.merge(conditions);
}
this.op = 'count';
if (!callback) {
return this;
}
this._count(callback);
return this;
};