Model.prototype.$where()

Parameters
  • argument «String|Function» is a javascript string or anonymous function
Returns:
  • «Query»

Creates a Query and specifies a $where condition.

Sometimes you need to query for things in mongodb using a JavaScript expression. You can do so via find({ $where: javascript }), or you can use the mongoose shortcut method $where via a Query chain or from your mongoose Model.

  1. Blog.$where('this.username.indexOf("val") !== -1').exec(function (err, docs) {});