1

I am beginner to MongoDB and I have Photo, Video ,Friend and User collection in mongoDB.

I am implementing search by name functionality, where i need to display user with his number of friends, number of photos and number of videos.

Right now, what i do is i execute find query on user collection and get user objects/documents.

Then i execute for loop through search result and for each user i get number of friends, photos and videos using individual queries as MongoDB doesn't support join.

To get rid of this for loop i am planning to embed friend id, photo id and video id into user object/document as below

@Document
Class User {

   List<String> friendIds;

   List<String> phtotIds;

   List<String> videoIds;
}

Is this correct way or is there any better solution?

Please guide.

Thanks

Community
  • 1
  • 1
Parth Solanki
  • 3,268
  • 2
  • 22
  • 41
  • possible duplicate of [References vs embeds in MongoDB](http://stackoverflow.com/questions/4950099/references-vs-embeds-in-mongodb) – Philipp Apr 02 '15 at 10:57
  • Found an even better duplicate: [MongoDB relationships: embed or reference?](http://stackoverflow.com/questions/5373198/mongodb-relationships-embed-or-reference/) – Philipp Apr 02 '15 at 11:00
  • Here are the according docs: http://docs.mongodb.org/manual/data-modeling/ – Markus W Mahlberg Apr 14 '15 at 21:18

0 Answers0