3

I am creating a project related to the blogs. Let say I have a blog post and in that, I want to maintain comments and likes against a post.

How can I achieve it? I have created a collection of blog post and in the same, I have an array of comments. But if I think of long term, this might not be the best approach.

Can someone please suggest me the best way to maintain such activity?

And is it possible to index a non unique key in a schema?

Like if I want to create another collection for comments and likes, how to retrieve the comments against a blog? I can but without index it would be slow when data is too much.

user9009353
  • 173
  • 1
  • 7
  • 2
    See https://stackoverflow.com/questions/5373198/mongodb-relationships-embed-or-reference. And yes, indexes don't have to be unique. – JohnnyHK Nov 16 '18 at 16:43
  • Can you please give me an example of making index on a non unique key? db.items.createIndex( { “item" : 1 } ) ? shall it work if item has similar values in a collection? – user9009353 Nov 16 '18 at 17:05

0 Answers0