[SERVER-1474] Ability to use count on embedded documents as a query condition for documents Created: 17/Aug/10  Updated: 06/Dec/22  Resolved: 19/May/17

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Mike Worth Assignee: Backlog - Query Team (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Universal


Assigned Teams:
Query
Participants:

 Description   

I am writing an application which tracks astronimical observations of targets. I have looked at documentation and it seems that I can use $elemMatch to find, for example, targets with at least one observation with (time > 1 week ago, type=photometry). However there doesn't seem to be a way to search for targets with at least 3 observations matching the criteria, or less than 2 matching observations etc.

This would be the equivilent of:
SELECT * FROM target JOIN observation [no need for ON clause because observation is embedded in target] WHERE observation.time>1281432059 AND observation.type='photometry' AND COUNT>=3 GROUP BY target.id

More info is at http://groups.google.com/group/mongodb-user/browse_thread/thread/a34e0b9296c8a075



 Comments   
Comment by Asya Kamsky [ 17/May/17 ]

This is possible to do using aggregation framework, there doesn't seem to be any work to be done here.

Generated at Thu Feb 08 02:57:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.