We will continue with our Collection User for data insertion. Let us consider various scenarios for inserting data in Collection User.
In, the above code snippet, we used getCollection() method in order to get the existing Collection User. An object of BasicDBObject is created and fields ("name" and "description") are appended with values. Output generated can be found by using MongoDB Compass.
The output for our Query is XYZ against field name. Data insertion in MongoDB against filed description.
The above query output is :
In the output, we can find that document is created with our unique custom id: