1. 删除
public boolean deleteDataCenterOwnersByUserId(String did,String uid) {
//参数封装
BasicDBObject query=new BasicDBObject();
query.put("_id", new ObjectId(did));
query.put("owners.id",new ObjectId(uid));
BasicDBObject _child=new BasicDBObject("id",new ObjectId(uid));
BasicDBObject update=new BasicDBObject("owners",_child);
BasicDBObject pull=new BasicDBObject("$pull",update);
try {
WriteResult r=DBManagerMongoDB.getInstance().Update("DataCenter", query,pull,true,false);
if(r.getN()>-1){
flag=true;
}
} catch (UnknownHostException e) {
e.printStackTrace();
}
return flag;
}
2.为数组添加下一项
BasicDBObject queryArea=new BasicDBObject();
queryArea.put("_id", new ObjectId(areaId));
BasicDBObject _childo=new BasicDBObject();
_childo.put("id", _o.get("_id"));
DBObject o=new BasicDBObject();
o.put("dc",_childo);
DBObject update=new BasicDBObject();
update.put("$push", o);
WriteResult rc=DBManagerMongoDB.getInstance().Update("CompanyArea", queryArea,update,true,false);