简体   繁体   English

在Spring数据MongoDB中转换MongoDb查询

[英]Convert MongoDb query in spring data mongodb

I have a document with an array. 我有一个带有数组的文档。 I want to delete the document if array exists and size is of 0. 如果数组存在且大小为0,我想删除文档。

I came up with this mongodb query(something similar) 我想出了这个mongodb查询(类似)

document.remove({ comments: { $exists: true, $size: 0 } })

please help me in converting this mongodb query to spring-data-mongodb or suggest me if there is any better solution for this. 请帮助我将此mongodb查询转换为spring-data-mongodb或建议我是否有更好的解决方案。

假设您有一个Document类。

mongoTemplate.remove(new Query(Criteria.where("comments").exists(true).size(0)), Document.class);

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

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