Read and write in single round trip

Hi everyone, is it possible to perform a read operations (e.g. a list of documents) and a write operation (e.g. insert one document) on the same collection with a single round trip? In particular I would like to guarantee the same order of execution (e.g. first, read all documents, then insert a new document).

Hello @Matteo_Tarantino, I don’t think you can perform a read and insert operation as a single call to the database. But, you can use a Transaction to perform the read and then the insert operation - atomically. You can control the application logic to make sure that one operation is complete and then perform the following operation. For example, NodeJS / JavaScript has Promises, callbacks and async-await constructs for such programming - see using Promises and callbacks with MongoDB NodeJS.

Thank you for the answer!