#Optimizing Member Updates in Teams Collection

8 messages · Page 1 of 1 (latest)

somber sandBOT
#

Let's say I have a teams collection that has a field called members which is a relationship field to users. As far as I understand it I can add new members like this

await payload.update({
  collection: 'teams',
  id: teamId,
  data: {
    members: [...existingMembers, newUserId],
  },
});

is there a better way? Do I need to fetch existing members whenever I need to add to or remove from members ?

lapis summitBOT
#

Original message from @fleet bridge - Moved from #general message

halcyon citrus
#

Hey @fleet bridge

You should pass existing members in for sure. The update function does not support atomic updates, so if you were to pass only a single member it would overwrite it to be that member only

fleet bridge
#

What if the members grow quite a bit ? Isn't this going to cause performance problems?

I guess I should create a collection myself like users_teams for the relation itself to solve this problem, right ?

halcyon citrus
#

Yep, if you anticipate it growing to a point of where it 'll be unmanagable as a field, then I would agree with you

fleet bridge
#

thanks a lot

halcyon citrus
#

My pleasure, have fun with it!