[Incorrect Question] : Which of the following are valid methods to insert a new document into a collection using the Node.js driver?

Issues:

If we read this question carefully, it says Which of the following are valid methods to insert a new document into a collection using the Node.js driver? , a new document, not many.

Then how, the answer will be insertMany

Solution:

The sentence should be revised.
The one suggestion is

Which of the following are valid methods to insert a new document or documents into a collection using the Node.js driver?

I think that

var a_new_document = { "_id" : 1 , "field" : "value" } ;

...insertMany( [ a_new_document ] ) ;

is a valid method to insert a new document. It might not be the best in all situations but it is certainly valid. And in some cases it might be the best. For example, you create an array in a for-loop. You do not want to have code specific for 1 document or many, so you insertMany, even if you have only one document.

1 Like