#community-help

Modifying Arrays in Typesense Documents

TLDR Jacob asked about modifying array elements in Typesense. Kishore Nallan suggested creating separate collections as a workaround.

Powered by Struct AI
3
11mo
Solved
Join the chat
Oct 18, 2022 (11 months ago)
Jacob
Photo of md5-c60456339dc3724ba99c3f7ca170d671
Jacob
06:48 AM
Hi guys! I have these list-documents that hold references to other entities in an array. Changes to these lists (adding and removing ids) come in events, on per change. Is there any API in Typesense to make that kind of changes to a document? What I’m looking for is “add id X to document.entities if it does not already exist” and “remove id X from document.entities if it exists”.

I’ve been looking through the docs but haven’t found anything, so I’m guessing it’s not supported. My idea to solve it is to create a separate collection and store each entry as it’s own document with {listId: 'YYY', itemId: 'XXX'}. It feels expensive, but I see no other way.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
07:03 AM
👋 we don't have a way to do add/remove elements from an array that way. Separate collection is not a bad idea because due to the use of inverted index the in memory representation would be about the same.
Jacob
Photo of md5-c60456339dc3724ba99c3f7ca170d671
Jacob
07:04 AM
Ah, great! Thanks for the quick reply Kishore Nallan!