您的位置:首页 > 数据库 > Mongodb

mongodb 批量更新,删除

2015-08-21 15:20 441 查看
public void batchUpdate(List<String> phoneList,String userId) {

Map<String, List<String>> map = new HashMap<String, List<String>>();

map.put("$in", phoneList);

DBObject queryValue = new BasicDBObject();

queryValue.put("phone", map);

queryValue.put("userId", userId);

DBObject updatedValue=new BasicDBObject();

updatedValue.put("sign", "true");

DBObject updateSetValue=new BasicDBObject("$set",updatedValue);

this.defaultMongoExt().getDbCollection().update(

queryValue, updateSetValue, false, true);

}

public void batchDeleteByIds(List<String> ids) {

Map<String, List<String>> map = new HashMap<String, List<String>>();

map.put("$in", ids);

DBObject dbObject = new BasicDBObject();

dbObject.put("id", map);

defaultMongoExt().getDbCollection().remove(dbObject);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: