According to this MongoDB spec https://www.mongodb.com/docs/v6.0/reference/operator/update/pull/ im trying to remove element from nested array. Structure:
{
"_id": "afcd4fdd-c78e-4a7c-af7e-51a9f4f15507",
"name": "aaa",
"ownerId": "1",
"supplyLimit": 1000,
"supplyUsed": 0,
"battleTally": 0,
"victories": 0,
"reqPoints": 5,
"cardEntities": [
{
"_id": "f2a16744-984d-4bbe-8bb2-b7b6ed3e202b",
"name": "aaaaa"
}
]
}
code:
@Query(value = "{'ownerId': ?0, 'id' : ?1}")
@Update("{ '$pull' : { 'cardEntities.$.id' : {'$eq' : ?2}} }")
long removeCard(String ownerId, String forceId, String cardId);
Result always has an error:
com.mongodb.MongoWriteException: Write operation error on server 127.0.0.1:27017. Write error: WriteError{code=28, message='Cannot use the part (_id) of (cardEntities._id) to traverse the element