Linking between multiple objects

Hello,

I have documents like this example :

{
“vendor_1_product_link” : “some data”,

},
{
“vendor_2_product_link”: " some data",

}

Can I access these datas with only “product_link” parameter ?

Yes, but for performance reasons you should ensure that you have an index for fields you intend searching and/or sorting on.

Your “schema” worries me a little in this regard, as it suggests you are perhaps misunderstanding the relationship between key and value. The implication of what you have shown is a potentially infinite number of keys, such that there is nothing in common between documents other than their “shape”. I would have expected to see something like:

{
  vendor: "vendor 1",
  product_link: "some data for vendor 1",
  ...
},
{
  vendor: "vendor 2",
  product_link: "some data for vendor 2",
  ...
},..

In which case, you would ensure an index (typically in a server Meteor.startup):

CollectionName._ensureIndex('product_link');

As you have described it you would need an _ensureIndex for 'vendor_1_product_link', 'vendor_2_product_link', …

1 Like