arrays - 从嵌入数组的内部文档中检索数据

标签 arrays spring mongodb

如何使用 Spring 从嵌入在 MongoDB 数组中的内部文档中检索数据?

{
    "project" : "proj001",
    "sourcevo" : [ 
        {
            "name" : "HpAlm",
            "type" : "database",
            "source" : "mysql",
            "toolvo" : {
                "url" : "https://123.com",
                "userName" : "123user",
                "password" : "password"
            },
            "dbvo" : {
                "servername" : "",
                "userName" : "",
                "password" : ""
            }
        }
    ]
}

最佳答案

使用 MongoDB db.collection.find() 方法,下面的查询将返回所有文档,其中 sourcevo 数组包含一个元素 name 字段等于“HpAlm”。

db.collection.find("{ sourcevo.name : { $eq : 'HpAlm' } }");

在 MongoTemplate 中,查询应该如下所示:

BasicQuery myQuery = new BasicQuery("{ sourcevo.name : { $eq : 'HpAlm' } }");
List<Document> docsList = mongoOperation.find(myQuery, Document.class);

关于arrays - 从嵌入数组的内部文档中检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37985313/

相关文章:

arrays - 我想在matlab中将char矩阵转换成数字

spring - 模型无法转换 - Spring Boot 和 Criteria API Join 中的内部错误

ruby-on-rails - 数组元素的排列,作为MongoID查询中的查询条件

javascript - Mongoose .save 恢复到原始值

mongodb 初始加载 - 即时构建 DBRef

php - 如何对 SplFixedArray 进行排序?

php - 在 PHP 中处理大量非常大的文件

c# - 读取存储在数组中的不同目录中的每个文件

java - 通过注释实现@Autowired @Lazy @Components 的最佳方法?

java - Bean创建异常: Injection of autowired dependencies failed