PouchDB query using parameters

Viewed 9493

Lets suppose we store cars (about 40MB) represented as JSON objects in a PouchDB, and we would like to search, based on the horsepower attribute. example in sql: select * from cars where HP > 100.

You can query pouchDB by key, but obviously HP is not the key of the document. Is there a way you can do this?

As far as I understand the map function,

function(doc) {
  if(doc.value) {
    emit(doc.value, null);
  }
}

it is not possible to access any variable within the outer scope of the function.

var horsePower = $scope.horsePowerInputField

function(doc) {
  if(doc.hp > horsePower) {
    emit(doc.value, null);
  }
}

so is there a possibility to query the database, parametrized based on non-key variables?

4 Answers
Related