For example when i send a message in a chat the updated_at field of the chat should be updated.
I want to get last updated chats for user#1 “Rick”. I don’t want to use $lookup for this reason:
“Performs a left outer join to an unsharded collection in the same database to filter in documents from the “joined” collection for processing.”
Instead i get the chat ids from the members collection then query the chats. This is slow and not efficient if the number of chats is big.
Hi again,
I implemented the outlier pattern but faced another problem.
As i said in the first question when a message is sent the updated_at field should be updated to get last updated chats of a user.
Now a group has many connected documents because of the pattern. Updating all the documents at once is very slow, i think it’s a bad idea doing so.
I am not sure why you chose so little number of users per document . I would go for like 500 maybe for one document.
If you see performance problems related to this specific search you can decrease the number of array elements. Having 5-10 elements does not make sense…
So for most chats you should have 1 maybe 2 documents in total .
Perhaps those very large groups should maybe get their own collection.
Why won’t you store the _id of each group main object in each extra object. This way you will only look for the single main document and not scan through all chats…
Also does chats have the message data as well or is it just a group repository?
Its better to have a groups collection and the messages in another collection with a group_id…
I hope there is no limit for the number of collections that we can create.
Why won’t you store the _id of each group main object in each extra object. This way you will only look for the single main document and not scan through all chats…
Do you mean this?
"chats": [
{
"id": 3,
"chat_id": 9, // the same as _id, i use id and chat_id for simplicity here
"members": [9, 10, 11, 12],
"main": false,
},
]
Otherwise i’m confused could you please show me a pseudo code example with sample chat data?
Also does chats have the message data as well or is it just a group repository?