简体   繁体   English

获取 java.lang.IllegalArgumentException “名称不能为空!” 更新 MongoDB 集合时

[英]Getting java.lang.IllegalArgumentException “Name must not be null!” when updating MongoDB collection

I am facing below issue when I am going to update a existing collection entry in mongoDB.当我要更新 mongoDB 中的现有集合条目时,我面临以下问题。 I am using Spring boot 2.0.我正在使用 Spring 启动 2.0。

my existing MongoDB collection entry is like below.我现有的 MongoDB 集合条目如下所示。 I'm going to update the "external_item" of below collection.我将更新以下集合的“external_item”。 It has a null key in that json posion.它在 json 位置有一个 null 键。

{
    "TestItem" : {
        "item1" : "value1"
    },
    "external_item" : {
        "" : "keyIsEmptyOfThisValue",
        "key2" : false
    },
    "links" : [],
    "createdDate" : ISODate("2020-05-10T05:24:44.014Z"),
    "updatedDate" : ISODate("2020-05-10T05:24:44.014Z")
}

For that I m using below payload with the PUT method with a REST API为此,我使用下面的有效负载和 PUT 方法和 REST API

{
"external_item" : {
        "" : "keyIsEmptyOfThisValue",
        "key2" : true
    }
}

when updating gives below issue.更新时出现以下问题。 It says Name must not be null.?它说名称不能是 null。? How can I get updated the MongoDB content in this way??如何以这种方式更新 MongoDB 内容?

java.lang.IllegalArgumentException: Name must not be null!
    at org.springframework.util.Assert.hasText(Assert.java:162)
    at org.springframework.data.mongodb.core.convert.QueryMapper$Field.<init>(QueryMapper.java:591)
    at org.springframework.data.mongodb.core.convert.QueryMapper.createPropertyField(QueryMapper.java:216)
    at org.springframework.data.mongodb.core.convert.UpdateMapper.createPropertyField(UpdateMapper.java:169)
    at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:122)
    at org.springframework.data.mongodb.core.convert.QueryMapper.convertSimpleOrDBObject(QueryMapper.java:359)
    at org.springframework.data.mongodb.core.convert.UpdateMapper.getMappedObjectForField(UpdateMapper.java:81)
    at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:123)
    at org.springframework.data.mongodb.core.MongoTemplate$11.doInCollection(MongoTemplate.java:1016)
    at org.springframework.data.mongodb.core.MongoTemplate$11.doInCollection(MongoTemplate.java:1007)
    at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:410)
    at org.springframework.data.mongodb.core.MongoTemplate.doUpdate(MongoTemplate.java:1007)
    at org.springframework.data.mongodb.core.MongoTemplate.updateFirst(MongoTemplate.java:985)
    at com.pearson.socket.core.dao.MongoDriverImpl.updateFirst(MongoDriverImpl.java:127)
    at com.pearson.socket.core.dao.AbstractDAOImpl.updateFirst(AbstractDAOImpl.java:92)```

There seems to be a bug somewhere in old versions of spring-data-mongodb that caused this.在旧版本的spring-data-mongodb中似乎存在导致此问题的错误。

Consider updating to newer spring-boot and spring-data-mongodb versions, eg I know that in spring-boot 2.2 that uses spring-data-mongodb 2.2.6 updating an entity with empty map key works.考虑更新到较新的spring-bootspring-data-mongodb版本,例如,我知道在spring-boot 2.2中使用spring-data-mongodb 2.2.6更新具有空 Z1D78DC8ED41244E5AEFEZB51 密钥的实体有效。

暂无
暂无

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

相关问题 Flyway 嵌套异常是 java.lang.IllegalArgumentException: Name must not be null - Flyway nested exception is java.lang.IllegalArgumentException: Name must not be null java.lang.IllegalArgumentException:参数绑定的名称不得为 null 或空 - java.lang.IllegalArgumentException: Name for parameter binding must not be null or empty 获取java.lang.IllegalArgumentException:存储库接口在初始化时不能为null吗? - getting java.lang.IllegalArgumentException: Repository interface must not be null on initialization? java.lang.IllegalArgumentException:方法不能为null - java.lang.IllegalArgumentException: Method must not be null java.lang.IllegalArgumentException:上下文不得为null - java.lang.IllegalArgumentException: Context must not be null java.lang.IllegalArgumentException:目标不能为空 - java.lang.IllegalArgumentException: Target must not be null JasperReports:获取java.lang.IllegalArgumentException:名称 - JasperReports: Getting java.lang.IllegalArgumentException: name 从Tomcat 7更新到Tomcat 8给了我java.lang.IllegalArgumentException:UrlResource中的URL不能为null - Updating from Tomcat 7 to Tomcat 8 gives me java.lang.IllegalArgumentException: URL must not be null from UrlResource spring data rest mongodb java.lang.IllegalArgumentException:PersistentEntity不能为null - spring data rest mongodb java.lang.IllegalArgumentException: PersistentEntity must not be null 获取异常:java.lang.IllegalArgumentException:无法添加到布局:约束必须为字符串(或为null) - getting Exception : java.lang.IllegalArgumentException: cannot add to layout: constraint must be a string (or null)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM