Skip to content

feat: Add MongoDB Document Backend With Embed Vs Reference - #8

Open
ThomasHartDev wants to merge 2 commits into
mainfrom
thomas/feat/mongo
Open

feat: Add MongoDB Document Backend With Embed Vs Reference#8
ThomasHartDev wants to merge 2 commits into
mainfrom
thomas/feat/mongo

Conversation

@ThomasHartDev

Copy link
Copy Markdown
Owner

The activity feed now has a document backend on the same ActivityStore port. Users embed their outbound following list so a home feed is one document read plus posts.find({ authorId: { $in } }). Posts live in their own collection with an authorId reference, because they grow without bound and would hit the 16 MiB BSON limit if nested. Inbound follows are edge documents for the same reason: celebrity inbound does not belong on the followee.

Follow dual-writes $addToSet on the user and a unique { followerId, followeeId } edge. Duplicate follow inserts (E11000, including a real-driver MongoServerError { code: 11000 }) are a no-op and still repair a missing embedded id. The unique pair index is independent of the synthetic edge _id. Keyset pagination uses $or so equal timestamps still total-order by _id. Same contract suite, plus tests that inspect the raw documents. Closes #7.

Users embed outbound following for the feed $in path. Posts and inbound
follow edges are referenced collections, with unique handle and edge
indexes and a compound $or keyset cursor.
A real driver throws MongoServerError { code: 11000, keyPattern }. Duck-type
that shape so handle_taken and idempotent follow work for any adapter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a MongoDB document backend (embed vs reference)

1 participant