#community-help

Organizing Document Updates in User-Focused Database

TLDR Gabriel had a question about managing document updates per user across various collections. CaptainCodeman and Jason suggested maintaining additional information about documents. After discussion, Gabriel proposed a solution involving a second map including collections.

Powered by Struct AI
7
18mo
Solved
Join the chat
Mar 16, 2022 (18 months ago)
Gabriel
Photo of md5-0a5e04bd1893bc2c14da1cf700f1aed1
Gabriel
02:24 PM
I was wondering:
I have a use case, where user updates his info and then all his documents need to be updated in the search, so I have a bunch of document id's to update, but I don't really know which collections they sit in.
So I can loop all collections and then do the import/update, which will then also throw some errors if the doc doesn't exist.
Is there a smarter way to do this?
CaptainCodeman
Photo of md5-d3a4ca49ba4aeb3b9d0cb7d846eb0989
CaptainCodeman
03:31 PM
sounds like you need to keep more information somewhere to be able to go directly to the relevant docs
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
04:00 PM
> I don't really know which collections they sit in.
How do you import documents into these different collections the first time around?
04:01
Jason
04:01 PM
Are you able to use that same logic to place the documents in the right collections during an update?
Gabriel
Photo of md5-0a5e04bd1893bc2c14da1cf700f1aed1
Gabriel
08:54 PM
Initially the user logs into a "zone", so when creating documents you know which collection they should go to.

But on the user itself, then I only store the doc id's, without the collection.

I guess I could store the collection as well, but that makes the structure a bit more nested.

To explain the use case:
1. user logs into like slack community 1.
2. creates a doc, the doc is uploaded to community 1.
3. doc id is stored on the user (createdDocs:[ 'id1', 'id2' ])
So if a user name changes, then all ids for docs should be updated.

I guess the solution would be to create a second map that includes the collections as well so:
docInfo : { 'col1' : [ 'id1', 'id2' ], 'col2' : ['id3', 'id4'] }
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
09:13 PM
> So if a user name changes, then all ids for docs should be updated.
Didn't get this part... Why do docs IDs change when a username changes?
Gabriel
Photo of md5-0a5e04bd1893bc2c14da1cf700f1aed1
Gabriel
10:19 PM
id's dont change.

What I meant is that all docs need to be updated with the new user info.