zoukankan      html  css  js  c++  java
  • Mongodb 级联删除查询操作

    ObjRelationPojo表一条记录

    public class YpObjRelationPojo implements Serializable {
    
    	@Id
    	private String id;					// '主键id'
    	@Field("sourceid")
    	private String sourceId;			//对象id
    	@Field("targetid")
    	private String targetId;			//对象id	
    	@Field("caseId")
    	private String caseId;				//案件id
    	@Transient							//配置透明属性
    	private int source;					// '关系起点   	不存数据库
    	@Transient
    	private int target;					// '关系终点	不存数据库
    	@Transient
    	private String color;
    	@Transient
    	private String relation;			// '关系名称'
    	@Field("relation_type")
    	@DBRef
    	private YpRelationTypePojo relation_type;
    	@Field("create_time")
    	private Date create_Time;			// '创建时间'
    

      省略了set,get方法

    @DBRef用于关联对象

    {
    "_id" : ObjectId("54a24e8a25600d768a4e13ac"),
    "sourceid" : "54a20a6dd9d886078991aa98",
    "targetid" : "54a209dfd9d886078991aa95",
    "caseId" : "100",
    "relation_type" : {
    "$ref" : "relationtype",
    "$id" : ObjectId("54a21b0ad9d886078991aa9e")
    }
    }

    如果需要查找出这条记录中的relation_type,查看相关联的对象

    我们需要使用点表示法则

    Id为relation_type表的记录id

    ObjectId objectId = new ObjectId(Id);

    Query query1=Query.query(Criteria.where("relation_type.$id").is(objectId));

    List<YpObjRelationPojo> r=mongoTemplate.find(query1, YpObjRelationPojo.class, "YpObjRelationPojo");

    找出之后,删除该字段

    Update update=new Update();

               update.unset("relation_type");

  • 相关阅读:
    CSS---@import
    C语言中float,double类型,在内存中的结构(存储方式)
    科普:字,字长,字节,位
    mysql的字段类型范围必须重视起来
    print,print_r,echo,var_dump,var_export比较
    常见编码格式
    php截取字符串,无乱码
    MYSQL配置详解
    Mysql主从复制,读写分离
    17173php招聘
  • 原文地址:https://www.cnblogs.com/bornteam/p/4193763.html
Copyright © 2011-2022 走看看