[GODRIVER-2582] Accept any value for "documents" in InsertMany Created: 11/Oct/22  Updated: 01/Nov/23  Resolved: 01/Nov/23

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 2.0.0

Type: Improvement Priority: Unknown
Reporter: Matt Dale Assignee: Steve Silvester
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to GODRIVER-3026 Optimize Collection.insert() Backlog
Epic Link: Go Driver 2.0: Driver
Backwards Compatibility: Major Change
Documentation Changes: Not Needed
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

Currently, Collection.InsertMany accepts a []interface for the list of documents to insert. However, that API often requires users to copy their existing slice of documents to a slice of type []interface, adding unnecessary repeated code and unnecessary data copies. Improve the API by changing the documents parameter type to interface and use reflection to require users to pass in a array type (i.e. array or slice).

This ticket was created based on a proposed improvement in a community PR.

Definition of done:

  • Change the documents parameter in InsertMany to any instead of []any.
  • Return an error if the value passed to the documents parameter is not a slice. That avoids ambiguity between inserting many documents and inserting a single document that is an array.
  • Add an InsertMany benchmark and compare the performance before/after. Require that there is no significant performance impact.


 Comments   
Comment by Githook User [ 01/Nov/23 ]

Author:

{'name': 'Ramit Mittal', 'email': 'commitemailoframit@protonmail.com', 'username': 'ramitmittal'}

Message: GODRIVER-2582 Accept any value for "documents" in InsertMany (#1437)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/9852b9c47cb93aa55d17310a0f4dd84b0dae6c7b

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