[SERVER-7095] Sample of three or more collections Created: 21/Sep/12 Updated: 15/Feb/13 Resolved: 21/Sep/12 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Question | Priority: | Major - P3 |
| Reporter: | Evgeny Kalibrov | Assignee: | sam.helman@10gen.com |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
PHP driver |
||
| Issue Links: |
|
||||
| Participants: | |||||
| Description |
|
Hello! There are collections city: {"_id", "name"}company: {"_id", "name", "cityID"}comments: {"_id", "text", "companyID"}You must select the last 10 comments on companies of a certain city. Now I select _id first of all companies in the city, and then the 10 comments received on _id $ db-> execute ('function () { var result = {}; var company = []; , {"title": 1, "_id": 1}). forEach (function (a) { var comments = []; ). limit (10). forEach (function (a) { result.comments [a._id] = Object.deepExtend (a, result [a._id]); comments.push (a._id); }); return result; }'); Esti's a better option to do what I need? |
| Comments |
| Comment by Jeremy Mikola [ 21/Sep/12 ] |
|
I resolved this because the SERVER project in JIRA is intended to be used for recording issues with the MongoDB server. Your question was a usage question, and a 10gen employee was already responding to your duplicate post of StackOverflow. Please follow up on the question there. |
| Comment by Evgeny Kalibrov [ 21/Sep/12 ] |
|
This is the right way to do two queries, where the first we select _id array, and the second looking at the array using "$in"? |
| Comment by Jeremy Mikola [ 21/Sep/12 ] |
|
This is already being answered on SO: http://stackoverflow.com/questions/12529663/mongodb-query-from-three-collections |