best method Implements followers with meteor/mongodb

52 Views Asked by At

I'm doing an app where users can follow topics. What is the best schema for implement with mongodb and meteor?

I thought to 2 solutions:

FIRST With one collection:

Schemas.Follow = new SimpleSchema({
userId: { type: String }
topicId: { type: String }
}

Pro: no problems with document 16MB limit Cons: performances for search are slow (?)

SECOND use ids array in users and topics collection

Schemas.User = new SimpleSchema({
...
follows: { type: [String] }
}

Schemas.Topic = new SimpleSchema({
...
followedBy: { type: [String] }
}

Pro: better performance of search Cons: problem of 16MB limit per document

Have you a better solution for mongodb and meteor?

Thanks!

1

There are 1 best solutions below

0
aedm On

A MongoDB ObjectID is a 12 byte object repesented by a string of 24 characters. Even if you assume a large storage overhead (say, 100 bytes per ID), a 16 megabyte document can store well over a hundred thousand IDs.

Assuming your users are humans, and they follow topics manually, it's most probably safe to store topic IDs in an array.