Hi team,
I have created a new function in Realm in which I want to do multiple inserts in my database.
The function is fairly simple. It just generates an array with given values and submits them via BulkWrite. The documents contain an id that should be unique (I have set an index for that) inside the collection.
THE PROBLEM: although I have set the ‘ordered’ to false, its behavior is not consistent.
Some of the times it skips the duplicates and stores all new documents, returning the list with the existing ones, and some others it stops in the first duplication.
The function is the following:
exports = async function insertManyPerformancesSkipDups(performances) {
const cluster = context.services.get("mongodb-atlas");
const perfCollection = cluster.db("main").collection("performances");
const operations = [];
performances.forEach(p => {
operations.push( { insertOne : { "document" : p } });
});
return await perfCollection.bulkWrite( operations, { ordered : false, writeConcern : { w : "majority", wtimeout : 2000 } })
}
I search the documentation and forums but I couldn’t figure out what might cause this inconsistency. Any ideas?
Thanks in advance