I can understand your frustration and this is due to projections still being in beta and also the lack in documentation.
Let me try and help you.
I have a blank database with projections enabled and a ‘testCategory’ projection (which is pretty much a copy and paste of yours) and all the system projections are enabled and running. (Note that starting Event Store with --run-projections doesn’t actually start the projections, you have to enable them)
fromCategory(‘pony’)
.foreachStream()
.when({
$init: function() {
return { count: 0,x:‘test’ }
},
$any: function(state, ev) {
state.count++;
}
})
``
I have a pony-derpy stream with some events in it
curl http://localhost:2113/streams/pony-derpy -H “accept:application/vnd.eventstore.atom+json”
{
“title”: “Event stream ‘pony-derpy’”,
“id”: “http://localhost:2113/streams/pony-derpy”,
“updated”: “2015-12-09T03:13:16.572957Z”,
“streamId”: “pony-derpy”,
“author”: {
“name”: “EventStore”
},
“headOfStream”: true,
“selfUrl”: “http://localhost:2113/streams/pony-derpy”,
“eTag”: “10;248368668”,
“links”: [
{
“uri”: “http://localhost:2113/streams/pony-derpy”,
“relation”: “self”
},
{
“uri”: “http://localhost:2113/streams/pony-derpy/head/backward/20”,
“relation”: “first”
},
{
“uri”: “http://localhost:2113/streams/pony-derpy/11/forward/20”,
“relation”: “previous”
},
{
“uri”: “http://localhost:2113/streams/pony-derpy/metadata”,
“relation”: “metadata”
}
],
“entries”: [
{
“title”: “10@pony-derpy”,
“id”: “http://localhost:2113/streams/pony-derpy/10”,
“updated”: “2015-12-09T03:13:16.572957Z”,
“author”: {
“name”: “EventStore”
},
“summary”: “eventType”,
“links”: [
{
“uri”: “http://localhost:2113/streams/pony-derpy/10”,
“relation”: “edit”
},
{
“uri”: “http://localhost:2113/streams/pony-derpy/10”,
“relation”: “alternate”
}
]
},
``
and here is the result you expected.
curl “http://localhost:2113/projection/testCategory/state?partition=pony-derpy”
{“count”:11,“x”:“test”}%
``