couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Browning <>
Subject Re: JSONQuery
Date Mon, 07 Sep 2009 17:12:53 GMT
Sorry to bring this thread back from the dead, but I just tried using
JSONQuery within a Couch view and everything seems to work fine. I'm
using the forked version of JSONQuery from here:

The only gotcha is that JSONQuery expects either a namespace function
or a window object to exist. So, I just create a fake window object.
Here's an example of a working map view with JSONQuery.js included via
a CouchApp macro. You could just as easily copy/paste its contents
directly into a view if you aren't using CouchApp.

var window = {};
// !code JSONQuery.js
JSONQuery = window["JSONQuery"]

function(doc) {
  var customers = JSONQuery("$.customers[?purchases > 21]", doc);
  for (var i = 0; i < customers.length; i++) {
    emit(customers[i].name, customers[i].purchases);

View raw message