Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-3872

Unrecognized pipeline stage name: '$setOnInsert'

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: 4.1.1
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      Standalone MongoDB instance in version 4.4.1.

      The App that runs the Mongo client is using Java 15.

      Description

      Using a standalone MongoDB instance in version 4.4.1 with a Java client that connects using the latest driver (`org.mongodb:mongodb-driver-sync:4.1.1`), I am getting an error when calling `findOneAndUpdate` with the $setOnInsert operator.

      Here is the query used:

      final List<Bson> updates = new ArrayList<>();
       updates.add(Updates.set("data", "test"));
       updates.add(Updates.setOnInsert("firstSeenTime", new Date()));
      final Document updatedDocument =
       this.visitorsCollection.findOneAndUpdate(
       eq("userId", "u1"), updates, new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER).upsert(true));
      

       

      The error:

      > Exception in thread "main" com.mongodb.MongoCommandException: Command
      > failed with error 40324 (Location40324): 'Unrecognized pipeline stage
      > name: '$setOnInsert'' on server A.B.C.D:XXXXX. The full
      > response is

      Unknown macro: {"ok"}

      at
      > com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:175)
      > at
      > com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:359)
      > at
      > com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:280)
      > at
      > com.mongodb.internal.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:100)
      > at
      > com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:490)
      > at
      > com.mongodb.internal.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:71)
      > at
      > com.mongodb.internal.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:255)
      > at
      > com.mongodb.internal.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:202)
      > at
      > com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:118)
      > at
      > com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:110)
      > at
      > com.mongodb.internal.operation.CommandOperationHelper$13.call(CommandOperationHelper.java:712)
      > at
      > com.mongodb.internal.operation.OperationHelper.withReleasableConnection(OperationHelper.java:620)
      > at
      > com.mongodb.internal.operation.CommandOperationHelper.executeRetryableCommand(CommandOperationHelper.java:705)
      > at
      > com.mongodb.internal.operation.CommandOperationHelper.executeRetryableCommand(CommandOperationHelper.java:697)
      > at
      > com.mongodb.internal.operation.BaseFindAndModifyOperation.execute(BaseFindAndModifyOperation.java:69)
      > at
      > com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:195)
      > at
      > com.mongodb.client.internal.MongoCollectionImpl.executeFindOneAndUpdate(MongoCollectionImpl.java:785)
      > at
      > com.mongodb.client.internal.MongoCollectionImpl.findOneAndUpdate(MongoCollectionImpl.java:765)

      If I get rid of the Updates.setOnInsert(...) call, then the update works but not as I would like. My purpose is to set some fields based on whether the document to update exists or not. Looking at the documentation, $setOnInsert should be supported:

      https://docs.mongodb.com/manual/reference/operator/update/#id1

      I am wondering if I misuse the API or if that's a bug.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            laurent.pellegrino@gmail.com Laurent Pellegrino
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: