For Import command, how MongoDB select the Destination Collection

Command:
mongoimport --uri=“mongodb+srv://m001-student:m001-mongodb-basics@sandbox.abcde.mongodb.net/sample_supplies” --drop sales.json

…Output…
sample_supplies" --drop sales.json
2020-10-22T07:28:41.529+0000 no collection specified
2020-10-22T07:28:41.529+0000 using filename ‘sales’ as collection
2020-10-22T07:28:43.539+0000 connected to: mongodb+srv://[REDACTED]@sandbox.yzxrb.mongodb.net/sample_supplies

In case there way two collections say sample1 and sample2 then above command will import the json file in which collection. In case of more than one collections, do we need to mandatorily give the collection name while importing and exporting?

When unsure always refer to the official documentation. See

For short answer, the database name is given as part of the URI. In your case, sample_supplies. The collection name is derived from the file name. In your case, it is sales derived from sales.json as indicated by the message using filename ‘sales’ as collection.

1 Like

Hi @Niket_Agrawal,

I hope you found @steevej-1495’s response helpful. Please let us know if you still have any questions.

~ Shubham

Thanks Steeve