MongoDB 批量更新/插入 即批量save或批量upsert 遇到的问题和解决方案
- 批量更新工具类完成
- 批量更新整个对象时候,因为没有$set符号导致异常,因此做了反射工具,再遍历字段去调用Update.set(k,v) 的方式去给字段赋值。(排除的字段目前是写死的,后续可以做成可配置)
- 批量更新时,对象有个属性是List< Object > 这个列表内的对象在插入时报错,说无法序列化:
java.lang.RuntimeException: json can't serialize type : class com.sy.sync.entity.po.mongo.ShopEntityBackTrackInfo$ReportGoods
at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:77) ~[mongo-java-driver-2.14.3.jar:?]
at com.mongodb.util.JSONSerializers$IterableSerializer.serialize(JSONSerializers.java:292) ~[mongo-java-driver-2.14.3.jar:?]
at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:79) ~[mongo-java-driver-2.14.3.jar:?]
at com.mongodb.util.JSONSerializers$MapSerializer.serialize(JSONSerializers.java:319) ~[mongo-java-driver-2.14.3.jar:?]
at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:79) ~[mongo-java-driver-2.14.3.jar:?]
at com.mongodb.util.JSONSerializers$MapSerializer.serialize(JSONSerializers.java:319) ~[mongo-java-driver-2.14.3.jar:?]
at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:79) ~[mongo-java-driver-2.14.3.jar:?]
at com.mongodb.util.JSONSerializers$MapSerializer.serialize(JSONSerializers.java:319) ~