Async API
Every write method has both a synchronous and an asynchronous version. Use the async versions in servers and applications where you do not want to block the event loop.
Available Async Methods
insertAsync/insertManyAsyncupdateOneAsync/updateManyAsyncdeleteOneAsync/deleteManyAsyncimportAsyncbackupAsync(on the database instance)rebuildIdAsync
Example
const user = await users.insertAsync({
name: 'Alice',
email: 'alice@example.com'
});
await users.updateOneAsync(
{ name: 'Alice' },
{ $set: { age: 29 } }
);
await users.deleteOneAsync({ name: 'Bob' });
All async write methods are protected by an internal lock to prevent race conditions.
Next: Learn about ID Generation.