package cn.com.capcloud.core.noentitydb;

import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;

import java.util.Map;

/**
 * @Author LiaoJiaHui
 * @Create 2022/9/21 13:38
 */
public class MongoTool {

    public static void save(String tableName, Map<String,Object> map, MongoTemplate mongoTemplate){
        Update update= new Update();
        for (String key : map.keySet()) {
            update.set(key,map.get(key));
        }
        update.set("_id",map.get("uuid"));
        Query query=new Query(Criteria.where("uuid").is(map.get("uuid")));
        mongoTemplate.upsert(query,update,tableName);
    }
}
