Skip to content

arrayFilters not working to update query in Kotlin #389

@chrismaandhika

Description

@chrismaandhika

I use Kotlin with jongo 1.5.0 in my project.

The data schema I am dealing with is like this:

{
    "_id" : ObjectId("62e351f2c4601cf024b31557"),
    "groupOrderId" : "123850",
    "orders" : [ 
        {
            "orderId" : "395875",
            "status" : "SUBMITTED",
            "confirmation" : [ 
                {
                    "contractNoteId" : "1234395875"
                }
            ]
        }, 
        {
            "orderId" : "395876",
            "status" : "SUBMITTED",
            "confirmation" : []
        }
    ],
    "platformCode" : "ABC"
}

I want to change the status field and add a new field inside a confirmation in one time with this way:

val writeResult = ordersCollection
                .update("{'groupOrderId': #}", groupOrderId)
                .with("{'\$set': {'orders.\$[o].confirmation.\$[c].transactionNumber': #, 'orders.$[o].status': #}}, {'arrayFilters': [{'o.orderId': #}, {'c.contractNoteId': #}]}",
                        orderStatus, transactionNumber, orderId, contractNoteId)

but it is not working and I always get this error:

com.mongodb.WriteConcernException: Write failed with error code 2 and error message 'No array filter found for identifier 'o' in path 'orders.$[o].status''
	at com.mongodb.operation.BaseWriteOperation.convertBulkWriteException(BaseWriteOperation.java:194)
	at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:155)
	at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:52)
	at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:213)
	at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:182)
	at com.mongodb.DBCollection.executeWriteOperation(DBCollection.java:356)
	at com.mongodb.DBCollection.update(DBCollection.java:588)
	at com.mongodb.DBCollection.update(DBCollection.java:507)
	at com.mongodb.DBCollection.update(DBCollection.java:482)
	at com.mongodb.DBCollection.update(DBCollection.java:459)
	at org.jongo.Update.with(Update.java:47)

Is there any fix I could do?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions