[SERVER-21649] $push and $addToSet should have a $limit modifier Created: 24/Nov/15  Updated: 06/Dec/22  Resolved: 08/Feb/18

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

Type: New Feature Priority: Major - P3
Reporter: Stefan Wójcik Assignee: Backlog - Query Team (Inactive)
Resolution: Done Votes: 3
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query
Participants:

 Description   

I believe on top of $slice that lets you control the size of the resulting array, there should be a modifier that allows Mongo to return an error when the resulting array size would exceed a certain limit.

$slice is nice when you can afford to lose the docs that didn't "make it" to the final array.

$limit (or whatever we call it) would be nice because an application could capture an exception when updating an array with too many items and then act on it in a smarter way than just dropping some items (which $slice already provides).



 Comments   
Comment by Asya Kamsky [ 08/Feb/18 ]

Document validation allows specifying maximum array size a couple of different ways, so closing this ticket as it's now possible.

Comment by Stefan Wojcik [ 09/Dec/15 ]

This can now be achieved by using document validation (new in v3.2) with a $size operator.

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