3

I was wondering what the best way to define this schema is:

enter image description here

Newsitem can only have 1 userID and 1 task ID. A Task can belong to many newsitems. A user can belong to many newsitems

I've searched for examples, but I'd say they are not a lot of examples. How can I do this with mongoose & mongodb ? I'd say that both User to newsitem and Task to Newsitem are one to many relations.

Olivier_s_j
  • 5,490
  • 24
  • 80
  • 126

1 Answers1

2

In Mongodb you can reference a collection within a schema so when you find() a document in newsitem mongoose does a find() in user and task, so instead of returning the newsitem document it returns the newsitem with the user and the task.

Mongoose population

Gabriel Llamas
  • 18,244
  • 26
  • 87
  • 112