def _upsert_samples_batch(self, samples_and_docs):
        """Upserts the given samples and their backing docs to the database.

        Args:
            samples_and_docs: a list of tuples of the form ``(sample, dict)``,
                where the dict is the sample's backing document
        """
        ops = []
        for sample, d in samples_and_docs:
            if sample.id:
                ops.append(ReplaceOne({"_id": sample._id}, d, upsert=True))
            else:
                d.pop("_id", None)
                ops.append(InsertOne(d))  # adds `_id` to dict

        try:
            self._sample_collection.bulk_write(ops, ordered=False)
        except BulkWriteError as bwe:
            msg = bwe.details["writeErrors"][0]["errmsg"]
            raise ValueError(msg) from bwe

        for sample, d in samples_and_docs:
            doc = self._sample_dict_to_doc(d)
            sample._set_backing_doc(doc, dataset=self)

            if sample.media_type == fom.VIDEO:
                sample.frames.save()
Upserts the given samples and their backing docs to the database.

        Args:
            samples_and_docs: a list of tuples of the form ``(sample, dict)``,
                where the dict is the sample's backing document
        
fiftyone/core/dataset.py