Can't get projections fromCategory to work as shown in the Rob Ashton guide.

Been following along with this guide and its covering projections based on category and running into some issues.

If I take this working projection.

fromStream(‘pony-derpy’)
.when({
$init: function() {
return { count: 0,x:‘test’ }
},
PonyBorn: function(state, ev) {
state.count++;
}
})

the results are as expected

{
“count”: 1,
“x”: “test”
}

However changing it to

fromCategory(‘pony’)
.foreachStream()
.when({
$init: function() {
return { count: 0,x:‘test’ }
},
PonyBorn: function(state, ev) {
state.count++;
}
})

and hitting http://localhost:2113/projection/testCategroy/state?partition=derpy give 200 response with no body (ContentLength:0). Sure I’m missing something simple or the guide is out of date. I’m using version 3.3.0 on a windows 10 box.

Any ideas?

The partition is ‘pony-derpy’, you should get results with http://localhost:2113/projection/testCategroy/state?partition=pony-derpy

Hmm, I must be missing something cause that doesn’t work either. I do notice that when change to the second, fromCategory, version the ‘Event Processed’ in the projection stats stays at 0. I also tried fromStreamsMatching but gave an error of ‘catalogStream is not supported in the projections mode’. This is really hard to debug given there is no feedback in the web UI and getting an empty 200 response.

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”}%

``

Okay so 2 things I found right away, yeah my lastest few tests weren’t running projection cause I didn’t know you had to enable all every time. Also going directly from your steps it works. So I think the culprit is the previous blog post that I was following. In that example he is dumping all events into a ‘ponies’ stream, then partitioning via something like,

fromStream('ponies')
    .whenAny(function(state, ev) {
        linkTo('pony-' + ev.data.id, ev)
    });

It appears that using fromCategory() on streams that are derived from linkTo calls might not be working? I can see the resulting streams and do the normal /streams/pony-x/0 type stuff with no issues. Can you confirm Pieter that you are seeing the same behavior (or lack thereof). Btw, thank you so much for taking the time to try and explain this!

Even with projections in beta would really prefer their usage, especially when compared to setting up a subscription like interface to talk to Redis or another db when locating the state fold on the eventStore makes so much more sense (especially in regards to i/o traffic).

I don’t see the same behaviour as you. Herewith my results

Hopefully you can see the screenshots.

Well now I’m more confused cause that works fine. Here is config for Postman to test this situation. Really don’t know what’s was different about my setup. Is there a way to look at the whole state of a projection that has partitions for more stats?

Usually, fromCategory() doesn’t work if $by_category system projection doesn’t run, which is the case by default.

I had a similar type of issue, and it was because my $by_category projection was not turned on.