Can you create index with a StreamID?

can you create index with a StreamID? for example:

type Test
  @createModel(accountRelation: LIST, description: "test.")
  @createIndex(fields: [{ path: "senderProfileId" }]){
  senderProfileId: StreamID! @documentReference(model: "BasicProfile")
  senderProfile: BasicProfile! @relationDocument(property: "senderProfileId")

You can only define indices in the ComposeDB composite, not on the model itself.

From my POV it seems your response is unrelated to the question because:

  1. above example is how docs and example apps have you implement index to better query chosen fields
  2. docs define composites as a category that contains models. Composites dont seem related to my question unless there’s something about StreamIDs that im not connecting in my mind - which is very possible

But that’s complex and not sure I need to understand that. I understand you can index by a string or DateTime - but im not certain if it will work for a StreamID. Ive searched and every example app only has createIndex directive using strings - so guess that’s it?

When you use @documentReference to define a relation to another Stream, that field automatically gets indexed. There’s no need to add a separate @createIndex directive.

CC @jpham @Justina - this could probably use some clarification in the docs.

CC @paul @StephH @cole - maybe we can add a clearer error message here if someone tries to add an index on a relation. Could be a good starter ticket for one of our new hires.

1 Like

Yes, that sounds like a good onboarding project! Thanks for clarifying this, @spencer