Retrieve events by type doesn't seem to work using $et-[typename] via API

Hi I am just getting started with things and was doing one test to see how you would retrieve events of a certain type.

According to Greg Youngs blog “*bytype projection built into the Event Store that does this to $et-{typename} that is optimized.” *

Based on this I assume I can retrieve all events for a certain type using ‘$et-[typename]’ as the stream name. However when I try this I get ‘Stream-Not-Found’

I am using the ‘ReadStreamEventsBackward’ method try this. Am I doing something wrong or did I misunderstand something?

I have enabled projections via “EventStore.SingleNode.exe -run-projections”

Here is the code I was using to test this as well (in case it helps)

        public void TestSaveSimpleEvent()
        {
            using (var connection = EventStore.ClientAPI.EventStoreConnection.Create(ConnectionSettings.Create()))
            {
                connection.Connect(endpoint);

                string streamId = "TestStream";
                TestEvent testEvent = new TestEvent()
                    {
                        TestId = Guid.NewGuid(),
                        TestName = "Some Data"
                    };

                string jsonEvent = Newtonsoft.Json.JsonConvert.SerializeObject(testEvent);
                byte[] eventRawBytes = Encoding.UTF8.GetBytes(jsonEvent);

                var metaData = new EventMetaData
                    {
                        MessageHeader = testEvent.Header,
                        TimeStamp = testEvent.Timestamp,
                        GroupId = streamId
                    };

                string jsonMetaData = Newtonsoft.Json.JsonConvert.SerializeObject(metaData);
                byte[] metaDataRawBytes = Encoding.UTF8.GetBytes(jsonMetaData);

                EventData eventData = new EventData(testEvent.EventId, testEvent.GetType().FullName, true, eventRawBytes,
                                                    metaDataRawBytes);

                connection.AppendToStream(streamId, ExpectedVersion.Any, this.GetEventData(testEvent, streamId));

            }

        }

    public void TestRetreiveEventByType()
    {
        using (var connection = EventStore.ClientAPI.EventStoreConnection.Create(ConnectionSettings.Create()))
        {
            connection.Connect(endpoint);

            // I always get SliceReadStatus.StreamNotFound
            var streamData = connection.ReadStreamEventsBackward("$et-" + typeof(TestEvent).FullName, 1,
                                                                     1, false);
            if (streamData.Status == SliceReadStatus.Success)
            {
                Console.WriteLine("Yay found something");
            }
        }
    }

Make sure it is --run-projections not -run-projections

I have tried:

EventStore.SingleNode.exe --run-projections

EventStore.SingleNode.exe -run-projections

none of these seem to work for *$et-{typename} * within the API

Figured it out. After starting EventStore with “EventStore.SingleNode.exe --run-projections”

I then needed to:

  1. browse to: “http://127.0.0.1:2113/web/projections.htm
  2. then select $by_event_type (I think this was the one I actually did this for everything)
  3. Press the Enable / start button (everything was set to ‘Not running’ by default)
    After this my test code worked

You can do the same logic via code as well:

        string eventStoreProjectionName = "$by_event_type";
        ProjectionsManager manager = new ProjectionsManager(logger, httpEndpoint);

bool running = false;
var allProjections = manager.ListAll();

JObject projections = JObject.Parse(allProjections);

JArray projectionArray = (JArray)projections[“projections”];
foreach (var p in projectionArray)
{
var name = (string)p[“name”];
var status = (string)p[“status”];
if (name == eventStoreProjectionName)
{
running = status == “Running” ? true : false;
break;
}
}

if (!running)
{
manager.Enable(eventStoreProjectionName);
}