Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arrayFilters not working to update query in Kotlin #389

Open
chrismaandhika opened this issue Jul 29, 2022 · 0 comments
Open

arrayFilters not working to update query in Kotlin #389

chrismaandhika opened this issue Jul 29, 2022 · 0 comments

Comments

@chrismaandhika
Copy link

chrismaandhika commented Jul 29, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant