Creating, updating, or deleting documents

In MongoDB, the document is the lowest atomic unit that can be addressed. As mentioned in Chapter 2, Understanding MongoDB Data Structures, a document is a JSON expression that contains a set of key:value pairs. The key is the name of the field and the value is the actual data used to form the document.

The MongoDB API consistently provides methods for both single and multiple operations. The generic form is (insert|update|delete)(One|Many)(). So, for example, if you wish to insert many documents, use insertMany(). If you only wish to delete only one, use deleteOne(), and so forth. 

Get MongoDB 4 Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.