0

Given the following collections:

// Users
{ "_id": ObjectId("1"), "username": "user1", "role": "developer" }
{ "_id": ObjectId("2"), "username": "user2", "role": "projectManager" }
{ "_id": ObjectId("3"), "username": "user3", "role": "testManager" }
{ "_id": ObjectId("4"), "username": "user4", "role": "developer" }

// Projects
{ "_id": ObjectId("1"), "title": "Monitoring System", ... }
{ "_id": ObjectId("2"), "title": "Search Engine", ... }
{ "_id": ObjectId("3"), "title": "IDE for Scala", ... }

// Contributions
{ "_id": ObjectId("1"), "projectId": ObjectId("1"), "userId": ObjectId("1") }
{ "_id": ObjectId("2"), "projectId": ObjectId("1"), "userId": ObjectId("2") }
{ "_id": ObjectId("3"), "projectId": ObjectId("1"), "userId": ObjectId("3") }
{ "_id": ObjectId("4"), "projectId": ObjectId("2"), "userId": ObjectId("1") }

Using ReactiveMongo, how do I get all the users who contributed to project 1? I need the whole document... not just the user id.

j3d
  • 9,492
  • 22
  • 88
  • 172
  • I saw this answer... but it's not what I'm look for. I think there are better ways like the aggregation framework, but I was unable to find an example that matches my needs. – j3d Aug 21 '15 at 21:22
  • That's because it doesn't exist. :) MongoDB queries can only span a single collection. – JohnnyHK Aug 23 '15 at 15:25

1 Answers1

0

There are no joins in mongodb in this case I would embedd your data and use true linking for example :

// Users

{_id : id, username: name, role: role, Contributions : [projectId1, projectId2, ..] }

That way you can do a simple find to get all user document that have a specific project id in the contributions array.

Embedding rich data into collections is what makes Mongodb so performant and flexible.

Sofian
  • 61
  • 4
  • No... this doesn't work because in my real case a project could have hundreds of thousands of contributors... – j3d Aug 21 '15 at 20:13