0

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!

Luca Romagnoli
  • 12,145
  • 30
  • 95
  • 157

1 Answers1

0

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.

aedm
  • 5,596
  • 2
  • 32
  • 36