-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: CRUD
`insertMany` uses bulkWrite internally. when a bulk write operation is constructed, we add each bulk write operation to "batches" and throw an error if the operation is not a document (specifically, checking if it's an array and throwing if it is). because `insertMany` uses bulkWrite, if a user provided a nested array in side an array of documents when inserting, they receive a rather unhelpful error from bulk write:
const client = new MongoClient(process.env.MONGODB_URI!); async function newFunction() { await client.connect(); await client .db('foo') .collection('bar') .insertMany([{ name: 'bailey' }, [{ name: 'bailey ' }]]); } newFunction(); // MongoInvalidArgumentError: Operation passed in cannot be an Array
It would be nice if we threw a more helpful error here instead, such as "MongoInvalidArgumentError: insertMany expects an array of documents, element <> was an array".
Acceptance Criteria:
- Detect invalid arguments in insertMany and throw a helpful error from insertMany if a non-document element is passed into insertMany