org.springframework.data.mapping.MappingException: Couldn’t find PersistentEntity for type class org.bson.Document!
没有设置 col name
@PostMapping("/updateMongo")
public Object updateMongo(@RequestBody MongoReq mongoReq) {
Map<String, Object> updateMap = mongoReq.getUpdateMap();
// updateMap.get("")
String id =(String) updateMap.get("id");
Query query = Query.query(Criteria.where("_id").is(
new ObjectId(id)
));
Update update = new Update();
for (Map.Entry<String, Object> stringObjectEntry : updateMap.entrySet()) {
String key = stringObjectEntry.getKey();
update.set(key, stringObjectEntry.getValue());
}
UpdateResult updateResult = mongoTemplate.updateFirst(query, update, Document.class,mongoReq.getCollectionName());
return updateResult;
// mongoTemplate.updateFirst(query, update, YourEntity.class);
}