Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
CommonJS require in map/reduce CouchDB 1.1.0
[info] [<0.313.0>] OS Process #Port<0.2368> Log :: function raised exception (new ReferenceError("require is not defined", ""))
[info] [<0.14096.0>] 127.0.0.1 - - 'GET' /reduce_test/_design/test/_view/test 200
{
"views": {
"lib": {
"foo": "exports.bar = 42;"
},
"test": {
"map": "function(doc) { emit(doc._id, require('views/lib/foo').bar); }",
"reduce": "function (keys, values, rereduce) { return require('views/lib/foo').bar; }"
}
}
}
$ curl http://localhost:5984
{"couchdb":"Welcome","version":"1.1.0"}
$ curl -X PUT http://localhost:5984/reduce_test
{"ok":true}
$ curl -X PUT http://localhost:5984/reduce_test/_design/test --data @ddoc.json
{"ok":true,"id":"_design/test","rev":"1-5a587aeb82027657db334265037a4692"}
$ curl -X POST http://localhost:5984/reduce_test -H "Content-Type: application/json" -d '{}'
{"ok":true,"id":"cd5869297d813d45d3e9f8016f001834","rev":"1-967a00dff5e02add41819138abb3284d"}
$ curl "http://localhost:5984/reduce_test/_design/test/_view/test?reduce=false"
{"total_rows":1,"offset":0,"rows":[
{"id":"cd5869297d813d45d3e9f8016f001834","key":"cd5869297d813d45d3e9f8016f001834","value":42}
]}
$ curl "http://localhost:5984/reduce_test/_design/test/_view/test"
{"rows":[
{"key":null,"value":null}
]}
^^^ Expected {"key":null,"value":42}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment