[JAVA-2436] Consider allowing zero-document inserts Created: 27/Jan/17  Updated: 19/Apr/17  Resolved: 19/Apr/17

Status: Closed
Project: Java Driver
Component/s: API, Query Operations
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Stephan Schroevers Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
is documented by JAVA-2499 Document that MongoCollection#insertM... Closed
Related
related to JAVA-2434 Empty insert causes subsequent querie... Closed
Backwards Compatibility: Fully Compatible

 Description   

This is a follow-up of JAVA-2434. Currently, providing a zero-length list or array to either DBCollection#insert or MongoCollection#insertMany yields an IllegalArgumentException. The question is whether the API can be relaxed to allow such empty inserts.

Rationale: the collection of documents inserted is generally dynamic, and may in fact be empty in some contexts. As it stands, callers must thus make sure to check for emptiness. It'd be nice if this "burden" can be pushed into the API, as it's easy to forget to add this check.

If implementing this feature request turns out to be infeasible, then I'd like to ask that the documentation on these methods be updated to clearly indicate that the input must be nonempty.



 Comments   
Comment by Jeffrey Yemin [ 19/Apr/17 ]

Hi Stephen,

I don't see it as an unreasonable burden to requires applications to make this check themselves. Applications are in the best position to know whether an empty list of documents is a normal condition. The driver should not be hiding bugs in applications where this was done inadvertently.

Also, as it stands every CRUD method in MongoCollection results in either a message sent to a MongoDB server or an exception. That's consistent and easy to understand, and I'd rather not change it.

I opened JAVA-2499 to track your request for clarification of the Javadoc for MongoCollection.

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