简体   繁体   English

无法使用休眠OGM从mongoDB中删除元素

[英]Unable to remove elements from mongoDB using hibernate OGM

I am using the following code to remove all the elements from mongoDB collection with a given parent_id : 我正在使用以下代码从具有给定parent_id mongoDB集合中删除所有元素:

final String strQuery = "db.Child.remove({'$query':{'PARENT_ID':'" + parentId + "'}})";
                final Query query = entityManager.createNativeQuery(strQuery, Child.class);
                query.executeUpdate();

However, I am getting the following exception: 但是,我收到以下异常:

Unexpected Exception
com.mongodb.util.JSONParseException:
db.Child.remove({'$query':{'CHILD_ID':'7313c076-dbaa-4557-b80f-68d040b65d82'}})

If I replace remove with find , I get the result back. 如果我remove find替换为find ,则会得到结果。 Dont know what is causing JSON parser error in the aboev mentioned native query. 在aboev提到的本机查询中,不知道是什么导致JSON解析器错误。

I am using hibernate-ogm version 4.3 Final with mongo-db 3.2 我在mongo-db 3.2中使用了hibernate-ogm版本4.3 Final

Hibernate OGM 4.3 did not support the remove operation for native queries. Hibernate OGM 4.3不支持本机查询的删除操作。

You should give OGM 5.0.2.Final a try: it should solve your issue as we added the support for quite a lot of other operations (and a lot of other fixes and improvements). 您应该尝试OGM 5.0.2.Final,因为它增加了对许多其他操作(以及许多其他修复和改进)的支持,因此应该可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM