4

I have finally go around to trying out meteor and I think it's really cool so far. I have been trying to link two Meteor.Collections() together like in a relational database.

For example let's say that the user enters and animal type like "Dog" and then other users could input types of dogs like "Doberman", "Labrador", etc.

Thanks in advance

edhedges
  • 2,722
  • 2
  • 28
  • 61

1 Answers1

4

Basically, the idea behind a document based Databases like MongoDB is not to try to imitate relational DBs. Try to see if you can add (embed) the types as a child of the animal type in the same collection instead of creating a link between two collections. With that said, there is still a way to link between to collections - The way to do that is outside of queries - meaning you get the results from one query and then pass them to the other query as paramaters (as you can see it's not an efficient way).

More background info can be found at - http://www.mongodb.org/display/DOCS/Schema+Design#SchemaDesign-EmbeddingandLinking

or - MongoDB and "joins"

Community
  • 1
  • 1
Gavriguy
  • 3,068
  • 3
  • 19
  • 23
  • I originally wanted to add some sort of array to the original collection but I don't know the syntax. This way I wouldn't really be having a relation but instead the data would just be with the original collection any advice? – edhedges May 05 '12 at 14:38
  • 1
    Here's the syntax: thing = { name: 'mr thing', tags: ['meteor', 'js'] } –  May 05 '12 at 23:38
  • or: thing = {name: 'mr thing', address: {house: '221b', street: 'Baker Street'}} –  May 05 '12 at 23:40