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");

  • 相关阅读:
    html5内容嵌入元素
    thinkphp默认路径访问报错
    LNMP安装教程
    wampserver的mysql启动与环境变量设置
    http响应详解_韩顺平PHP视频听课笔记
    http请求详解,防盗链技术_韩顺平PHP视频听课笔记
    使用js写一个作用于xml文件的ajax
    使用js创建一个简单的ajax
    js写一个ajax错误规避
    使用js写一个原生态简单的ajax
  • 原文地址:https://www.cnblogs.com/bornteam/p/4193763.html
Copyright © 2011-2022 走看看