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);
}
// inherit mquery
mquery.call(this, this.mongooseCollection, options);
if (conditions) {
this.find(conditions);
}
}
/*!
* inherit mquery
*/
Query.prototype = new mquery;
Query.prototype.constructor = Query;
Query.base = mquery.prototype;
/**
* Flag to opt out of using `$geoWithin`.
*
* mongoose.Query.use$geoWithin = false;
*
* MongoDB 2.4 deprecated the use of `$within`, replacing it with `$geoWithin`. Mongoose uses `$geoWithin` by default (which is 100% backward compatible with $within). If you are running an older version of MongoDB, set this flag to `false` so your `within()` queries continue to work.
*
* @see http://docs.mongodb.org/manual/reference/operator/geoWithin/
* @default true
* @property use$geoWithin
* @memberOf Query
* @receiver Query
* @api public
*/
// inherit mquery
mquery.call(this, this.mongooseCollection, options);
if (conditions) {
this.find(conditions);
}
}
/*!
* inherit mquery
*/
Query.prototype = new mquery;
Query.prototype.constructor = Query;
Query.base = mquery.prototype;
/**
* Flag to opt out of using `$geoWithin`.
*
* mongoose.Query.use$geoWithin = false;
*
* MongoDB 2.4 deprecated the use of `$within`, replacing it with `$geoWithin`. Mongoose uses `$geoWithin` by default (which is 100% backward compatible with $within). If you are running an older version of MongoDB, set this flag to `false` so your `within()` queries continue to work.
*
* @see http://docs.mongodb.org/manual/reference/operator/geoWithin/
* @default true
* @property use$geoWithin
* @memberOf Query
* @receiver Query
* @api public
*/
// inherit mquery
mquery.call(this, this.docoomentCollection, options);
if (conditions) {
this.find(conditions);
}
}
/*!
* inherit mquery
*/
Query.prototype = new mquery;
Query.prototype.constructor = Query;
Query.base = mquery.prototype;
/**
* Flag to opt out of using `$geoWithin`.
*
* docooment.Query.use$geoWithin = false;
*
* MongoDB 2.4 deprecated the use of `$within`, replacing it with `$geoWithin`. Docooment uses `$geoWithin` by default (which is 100% backward compatible with $within). If you are running an older version of MongoDB, set this flag to `false` so your `within()` queries continue to work.
*
* @see http://docs.mongodb.org/manual/reference/operator/geoWithin/
* @default true
* @property use$geoWithin
* @memberOf Query
* @receiver Query
* @api public
*/
// inherit mquery
mquery.call(this, this.mongooseCollection, options);
if (conditions) {
this.find(conditions);
}
}
/*!
* inherit mquery
*/
Query.prototype = new mquery;
Query.prototype.constructor = Query;
Query.base = mquery.prototype;
/**
* Flag to opt out of using `$geoWithin`.
*
* mongoose.Query.use$geoWithin = false;
*
* MongoDB 2.4 deprecated the use of `$within`, replacing it with `$geoWithin`. Mongoose uses `$geoWithin` by default (which is 100% backward compatible with $within). If you are running an older version of MongoDB, set this flag to `false` so your `within()` queries continue to work.
*
* @see http://docs.mongodb.org/manual/reference/operator/geoWithin/
* @default true
* @property use$geoWithin
* @memberOf Query
* @receiver Query
* @api public
*/
if (collection) {
this.mongooseCollection = collection;
}
if (model) {
this.model = model;
}
// this is needed because map reduce returns a model that can be queried, but
// all of the queries on said model should be lean
if (this.model && this.model._mapreduce) {
this.lean();
}
// inherit mquery
mquery.call(this, this.mongooseCollection, options);
if (conditions) {
this.find(conditions);
}
}