code: @CheckReturnValue
    private LocalSyncWriteModelContainer replaceOrUpsertOneFromRemote(
        final NamespaceSynchronizationConfig nsConfig,
        final BsonValue documentId,
        final BsonDocument remoteDocument,
        final BsonDocument atVersion
    ) {
      final MongoNamespace namespace = nsConfig.getNamespace();
      final ChangeEvent<BsonDocument> event;
      final Lock lock =
          this.syncConfig.getNamespaceConfig(namespace).getLock().writeLock();
      lock.lock();
      final BsonDocument docForStorage;
      final CoreDocumentSynchronizationConfig config;
      try {
        config = syncConfig.getSynchronizedDocument(namespace, documentId);
        if (config == null) {
          return null;
        }
  
        docForStorage = sanitizeDocument(remoteDocument);
  
        config.setPendingWritesComplete(HashUtils.hash(docForStorage), atVersion);
  
        event = ChangeEvents.changeEventForLocalReplace(namespace, documentId, docForStorage, false);
      } finally {
        lock.unlock();
      }
  
      final LocalSyncWriteModelContainer container = newWriteModelContainer(nsConfig);
  
      container.addDocIDs(documentId);
      container.addLocalWrite(new ReplaceOneModel<>(
          getDocumentIdFilter(documentId),
          docForStorage,
          new ReplaceOptions().upsert(true)));
      container.addLocalChangeEvent(event);
      container.addConfigWrite(new ReplaceOneModel<>(
          CoreDocumentSynchronizationConfig.getDocFilter(namespace, config.getDocumentId()
          ), config));
  
      return container;
    }
docs: Replaces a single synchronized document by its given id with the given full document
  replacement. No replacement will occur if the _id is not being synchronized.
  
  @param nsConfig  the namespace synchronization config of the namespace where the document
  lives.
  @param documentId the _id of the document.
  @param remoteDocument   the replacement document.