Mong0db 中2.9.3java链接驱动工具类编写

public class DbObjectBuilderWraper {
public static DbObjectBuilderWraper newInstance(){
return new DbObjectBuilderWraper();
}
private BasicDBObjectBuilder builder;
public DbObjectBuilderWraper(BasicDBObjectBuilder builder) {
this.builder = builder;
}
public DbObjectBuilderWraper() {
this.builder = new BasicDBObjectBuilder();
}
public DBObject get(){
return builder.get();
}
private boolean isNull(Object obj){
if(obj == null || obj.equals(""))return true;
if(obj instanceof Long && obj.equals(0L))return true;
if(obj instanceof Integer && obj.equals(0))return true;
return false;
}

public DbObjectBuilderWraper addOption(String key, Object obj){
if(obj == null || obj.equals(""))return this;
if(obj instanceof BasicDBObject)
this.builder.append(key, obj);
if(obj.getClass().isArray())
return in(key, (Object[])obj);
if(obj instanceof Collection)
return in(key, ((Collection)obj).toArray());

this.builder.append(key, obj);
return this;
}
public DbObjectBuilderWraper lt(String key, Object obj){
if(obj == null || obj.equals(""))return this;
Map<String, Object> map = new HashMap<String, Object>();
map.put("$lt", obj);
this.builder.append(key, map);
return this;
}
/**
* 不符,支持数组
* {_id:xxx, groups:['a','b','c'}]
* ne("groups", "a")//表示不含"a"
* @param key
* @param obj
* @return
*/
public DbObjectBuilderWraper ne(String key, Object obj){
if(obj == null || obj.equals(""))return this;
Map<String, Object> map = new HashMap<String, Object>();
map.put("$ne", obj);
this.builder.append(key, map);
return this;
}

public DbObjectBuilderWraper gt(String key, Object obj){
if(obj == null || obj.equals(""))return this;
Map<String, Object> map = new HashMap<String, Object>();
map.put("$gt", obj);
this.builder.append(key, map);
return this;
}
public DbObjectBuilderWraper lte(String key, Object obj){
if(obj == null || obj.equals(""))return this;
Map<String, Object> map = new HashMap<String, Object>();
map.put("$lte", obj);
this.builder.append(key, map);
return this;
}
public DbObjectBuilderWraper gte(String key, Object obj){
if(obj == null || obj.equals(""))return this;
Map<String, Object> map = new HashMap<String, Object>();
map.put("$gte", obj);
this.builder.append(key, map);
return this;
}
public DbObjectBuilderWraper addOptionBetween(String key, Object start, Object end){
Map<String, Object> map = new HashMap<String, Object>();
if(!isNull(start))map.put("$gte", start);
if(!isNull(end))map.put("$lt", end);
if(map.isEmpty())return this;
this.builder.append(key, map);
return this;
}
public DbObjectBuilderWraper in(String key, Object[] items){
if(items == null || items.length == 0)return this;
Map<String, Object> map = new HashMap<String, Object>();
map.put("$in", items);
this.builder.append(key, map);
return this;
}
public DbObjectBuilderWraper in(String key, Collection items){
if(items == null || items.isEmpty())return this;
Map<String, Object> map = new HashMap<String, Object>();
map.put("$in", items);
this.builder.append(key, map);
return this;
}
public DbObjectBuilderWraper nin(String key, Object[] items){
if(items == null || items.length == 0)return this;
Map<String, Object> map = new HashMap<String, Object>();
map.put("$nin", items);
this.builder.append(key, map);
return this;
}
public DbObjectBuilderWraper nin(String key, Collection items){
if(items == null || items.isEmpty())return this;
Map<String, Object> map = new HashMap<String, Object>();
map.put("$nin", items);
this.builder.append(key, map);
return this;
}
public DbObjectBuilderWraper eqOrIn(String key, Object[] vals) {
if(vals != null && vals.length > 1){
return this.in(key, vals);
}
if(vals != null && vals.length == 1 && vals[0] != null){
return this.addOption(key, vals[0]);
}
return this;
}
public DbObjectBuilderWraper append(String key, BasicDBObject obj){
this.builder.append(key, obj);
return this;
}
/**
* 添加$or过滤,类似于
* BasicDBList ls = new BasicDBList();
ls.add(new BasicDBObject("foo", new BasicDBObject("$exists", false)));
ls.add(new BasicDBObject("foo", 1));
ls.add(new BasicDBObject("bar", 1));
query.append("$or", ls);
* @param ls
* @return
*/
public DbObjectBuilderWraper or(DBObject ... items){
this.builder.append("$or", items);
return this;
}
/**
* 是否存在
* @param col
* @param flag
* @return
*/
public DbObjectBuilderWraper exists(String col, boolean flag){
this.builder.append(col, new BasicDBObject("$exists", flag));
return this;
}
/**
* 添加js过滤,相当于: new BasicDbObject("$where", "this.rank > 1");
* @param expression
* @return
*/
public DbObjectBuilderWraper where(String expression){
if(isNull(expression))return this;
this.builder.append("$where", expression);
return this;
}
/**
* Like处理
* @param key
* @param content
* @return
*/
public DbObjectBuilderWraper like(String key, String content){
if(isNull(content))return this;
Pattern pattern = Pattern.compile("^.*" + content+ ".*$", Pattern.CASE_INSENSITIVE);
this.builder.append(key, pattern);
return this;
}

}



package com.tintop.frame.mongo;


import java.util.ArrayList;
import java.util.List;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


import com.mongodb.DB;
import com.mongodb.Mongo;
import com.mongodb.MongoOptions;
import com.mongodb.ReadPreference;
import com.mongodb.ServerAddress;
import com.tintop.frame.util.ConfigProperties;
import com.tintop.frame.util.FrameException;


public class MongoDbConUtils {
protected static Log log = LogFactory.getLog(MongoDbConUtils.class);
private static Mongo mongo = null;
/**
* 数据库
*/
public synchronized static Mongo getMongo(){
if(mongo == null){
String str = ConfigProperties.get().getMongoHost();
mongo = createMongo(str);
}
return mongo;
}


/**
* 获取数据库
* @return
*/
public static DB getDb(String name){
return getMongo().getDB(name);
}
/**
* 使用默认参数,创建Mongo并执行自动验证
* @param str
* @param opt
* @return
*/
public static Mongo createMongo(String str){
MongoOptions opt = new MongoOptions();
opt.connectionsPerHost = Integer.valueOf(ConfigProperties.getProp("mongodbpoolsize", 1000));
opt.autoConnectRetry = true;
opt.threadsAllowedToBlockForConnectionMultiplier = 20;
opt.maxWaitTime = 12000;
opt.connectTimeout = 6000;
opt.maxAutoConnectRetryTime = 12000;
opt.socketTimeout = 60000;
opt.socketKeepAlive = true;
opt.readPreference = ReadPreference.secondaryPreferred();
return createMongo(str, opt);
}
/**
* 创建Mongo并执行自动验证
* @param str
* @param opt
* @return
*/
public static Mongo createMongo(String str, MongoOptions opt){
mongo = new Mongo(getAddr(str), opt);
//考虑是否需要验证
String mongodbadminpwd = ConfigProperties.getProp("mongodbadminpwd");
if(mongodbadminpwd != null && !mongodbadminpwd.trim().equals("")){
try {
if(!mongo.getDB("admin").authenticate("admin", mongodbadminpwd.trim().toCharArray())){
log.warn("连接mongodb时验证失败,请确认是否在mongodb的admin数据库中设置了admin帐户的密码?");
}
} catch (Exception e) {
log.debug(e.getMessage());
}
}
return mongo;
}

private static List<ServerAddress> getAddr(String hoststr){
if(hoststr == null || hoststr.equals("")){
hoststr = "localhost:27017";
}
String[] str = hoststr.split(",");
List<ServerAddress> addrs = new ArrayList<ServerAddress>();
for(String s : str){
if(s == null || s.trim().equals(""))continue;
s = s.trim();
String host = s;
String port = "27017";
if(s.indexOf(":") >= 0){
host = s.substring(0, s.indexOf(":"));
port = s.substring(s.indexOf(":") + 1);
}
try {
addrs.add(new ServerAddress(host, Integer.parseInt(port)));
} catch (Exception e) {
log.error("连接到Mongo数据库:" + host + ":" + port + "失败!", e);
}
}
if(addrs.isEmpty()){
throw new FrameException("无有效的Mongo数据库连接!");
}
return addrs;
}
}






package com.tintop.frame.mongo;




import com.mongodb.BasicDBObjectBuilder;


/**
 * MongoDb操作的助手类
 * @author dell
 *
 */
public class MongoDbUtils {

/**
* 根据名称获取DBCollectionWraper
*/
public static DBCollectionWraper getCollectionWraper(String name){
return new DBCollectionWraper(name);
}
/**
* 获取DBObjectBuilder
*/
public static DbObjectBuilderWraper getDbObjectBuilderWraper(){
return new DbObjectBuilderWraper(new BasicDBObjectBuilder());
}

//企业导入配置表
public final static String TB_IMPORTCONFIG = "tb_importconfig";
//任务表
public static String TB_TASK = "tb_task";
//短信表
public static String TB_SMS_RECORD = "tb_sms_record";
//操作日志表
public static String TB_OPTLOG = "tb_optlog";
//测试表
public static String TB_TEST = "tb_test";
/**
* 企业导入配置表:
* 字段
* compCode  String 企业代码
* name String 导入配置名,同dx的importconfig元素的name定义
* fileid String 模板文件的文件id
* headerrow 
* datarow
* title
* custparams String 形式如:foo=bar \n name=jerry \n ....
* 用户自定义参数名
*/
public static DBCollectionWraper getTbImportConfig(){
return new DBCollectionWraper(TB_IMPORTCONFIG);
}
/**
* 企业任务表:
* //属于某个企业,空表示系统任务
Long compId;
//建立时间
Long createTime;
//参数值,采用xml序列化
String dataXml;
//类别,由产生者自行给定, show:
String type;
//类别名称
String typeName;
//失败时最多重试次数,show
Integer maxResetTimes;
//当前执行的次数,如果为publish类型的消息,此处存储执行出错次数最小的数值,show
Integer executedTimes;
//最后一次执行,show
Long lastExecute;
//最后一次执行时的错误消息,show
String lastMessage;
//状态:0未执行,1等待重新调度,2出错,3正在执行中,4.已完成 tb_taskinfo_status
Integer status;
//任务类型:1.queue,2.publish 发布订阅型,需要设置frame.hostnodes的系统参数指定所有的主机节点,当最后一个节点成功执行后该任务被删除
Integer queueType;
//下次执行时间
Timestamp nextExecuteTime;
//任务说明
String notes;
//执行结果说明
String resultmsg;
//结果数据,将对象序列化成xml存储,供查看执行结果时使用
String resultdata;
//创建者
Long createUid;
*/
public static DBCollectionWraper getTbTask(){
return new DBCollectionWraper(TB_TASK);
}


/**
* 操作日志表
* Long compId 所属企业(适用于企业帐户)
* String name 日志名称
* int optType 操作类型 1新加,2修改,3删除 tb_opterationlogrecord_optType
* String jsonData 对象序列化为json后存储
* String oldJsonData 原对象序列化为json后存储,主要是修改前的数据
* String message 消息
* Long createUid 操作员
* String createFromIp 操作IP
* Long createTime 操作时间
*/
public static DBCollectionWraper getTbOptLog(){
return new DBCollectionWraper(TB_OPTLOG);
}
/**
* 测试表
* String name;
* long time;
* int sex;
*/
public static DBCollectionWraper getTbTest(){
return new DBCollectionWraper(TB_TEST);
}
//自定义表单表
public static String TB_FORMDEFINE = "tb_formdefine";
/**
* 自定义表单
* String code; //表单代码
* String name; //表单名称
* Long compId; //所属企业
* Boolean detailFlag;//是否为子表单
* Integer status; //1启用,2停用
* String notes; //备注
* String js;//生成的js代码
* Long updateUid;
* Long updateTime;
*/
public static DBCollectionWraper getTbFormDefine(){
return new DBCollectionWraper(TB_FORMDEFINE);
}

//自定义表单表字段
public static String TB_FORMFIELDDEFINE = "tb_formfielddefine";
/**
* 自定义表单字段
* String formCode;//所属表单
* String code;//代码
* String name;//名称
* Integer type;//1.文本,2.整数,3.数字,4.布尔,6.日期,7.时间,8.字典数据,9.预定义选择器,10.表格,11.预定义组件
* boolean required;//是否必填写
* double maxNum; //最大值
* double minNum; //最小值
* Date startDate; //适用于日期验证,开始时间
* Date endDate; //适用于日期验证,结束时间
* String regex; //正则表达式验证
* String dgroup; //适用于字典下拉框
* String pickerClass; //适用预定义的Picker选择器
* String gridClass; //适用于表格类型的组件
* String componentClass; //适用于自定义的组件
*/
public static DBCollectionWraper getTbFormFieldDefine(){
return new DBCollectionWraper(TB_FORMFIELDDEFINE);
}
//组件企业特定配置存储
public static String TB_COMPONENT_CONFIG = "tb_component_config";
/**
* 操作日志表
* String compCode 所属企业代码
* String className js类名
* String jsconfig js配置
*/
public static DBCollectionWraper getTbComponentConfig(){
return new DBCollectionWraper(TB_COMPONENT_CONFIG);
}
//企业菜单的特定配置
public static String TB_MENU_CONFIG = "tb_menu_config";
/**
* 企业菜单的特定配置
* Long compId 企业编号
* Long menuId 菜单编号
* String text 菜单标题
* Integer sortIndex 排序号
*/
public static DBCollectionWraper getTbMenuConfig(){
return new DBCollectionWraper(TB_MENU_CONFIG);
}
//用户的快捷菜单设置
public static String TB_USER_FLAT_MENU = "tb_user_flat_menu";
/**
* 用户的快捷菜单
* Long userId 用户编号
* Long compId 企业编号
* Long menuId 菜单编号
* String text 快捷操作显示的名称
* String appText 应用名称
* String parentText 上级名称
* Integer sortIndex 序号
*/
public static DBCollectionWraper getTbUserFlatMenu(){
return new DBCollectionWraper(TB_USER_FLAT_MENU);
}
/**
* 登录日志
* Long userId
* Long compId
* Long loginTime
* String loginIp 
* String location //登录位置
* int postype 0 最后一次登录,1倒数第二次登录
*/
public static String TB_LOGIN_LOGER = "tb_login_loger";
public static DBCollectionWraper getTbLoginLoger(){
return new DBCollectionWraper(TB_LOGIN_LOGER);
}
/**
* 用户发件箱
* String title; //标题
* String content; //内容
* String uids;//接收人的id列表以;隔开
* String groupids;//接收用户组的id列表以;隔开
* boolean allflag; //是否发送给所有人
* boolean repflag; //是否支持回复
* Long pubdate;//发布时间
* String pubman;//发布人
* String appendFile1;//附件1
* String appendFile2;//附件2
* Long createUid; //建立人
* Long createTime; //建立时间
* Long compId; //所属企业
* Long typeId;//分类
*/
/*public static String TB_USER_MESSAGE = "tb_user_message";
public static DBCollectionWraper getTbUserMessage(){
return new DBCollectionWraper(TB_USER_MESSAGE);
}*/
/**
* 用户收件箱
* Long compId; //所属企业
* Long uid; //所属用户
* String fromMsgId;//源消息mongodb的编号
* Long reciveTime; //接收时间
* Boolean readflag; //是否为已读

* String title; //标题
* String content; //内容
* String uids;//接收人的id列表以;隔开
* String groupids;//接收用户组的id列表以;隔开
* boolean allflag; //是否发送给所有人
* boolean repflag; //是否支持回复
* String pubman;//发布人
* Long pubdate;//发布时间
* String appendFile1;//附件1
* String appendFile2;//附件2
* Long typeId;//分类

* 考虑扩展:是否需要发送短信,是否需要发送邮件....
* -------------------
*/
/*public static String TB_USER_MESSAGE_RECIVE = "tb_user_message_recive";
public static DBCollectionWraper getTbUserMessageRecive(){
return new DBCollectionWraper(TB_USER_MESSAGE_RECIVE);
}*/
/**
* 用户任务
* Long compId; //所属企业
* Integer ctype; //日程类型:1个人日程,2部门日程,3系统日程 
* Long uid; //所属用户
* Long createUid; //创建人
* Long createTime; //建立时间
* String title; //标题
* String content; //内容
* Long startTime; //开始时间
* Long endTime; //结束时间
* Boolean fullday;
* String tiptype;//是否需要提醒tb_user_task_tiptype  -1:不提醒,0:开始时提醒,0.5d:提前关天, 5h:提前5小时, 30m提前30分钟。。。
* Boolean mailflag; //是否需要邮件提醒
* String sendMailId; //邮件发送的内部id,发送后填写
* Boolean smsflag;//是否需要短信提醒
* String sendSmsId; 
* String file1; //附件文件id
* String file2;
* String file3;
* -------------------
*/
/*public static String TB_USER_TASK = "tb_user_task";
public static DBCollectionWraper getTbUserTask(){
return new DBCollectionWraper(TB_USER_TASK);
}*/
/**
* 用户提醒
* Long uid; //所属用户
* Long compId; //公司id
* Long remindRecordId; //来源提醒
* String title; //标题 
* Boolean readflag; //是否已读
* Timestamp readtime; //阅读时间
* Boolean needmail; //是否需要发送邮件
* Integer mailresult; //是否已发送邮件tb_remind_mailresult 0.未发送,1.已发送,2发送失败
* Timestamp mailtime; //邮件发送时间
* Boolean needsms; //是否需要发送短信
* Integer smsresult; //是否已发送短信tb_remind_smsresult  0.未发送,1.已发送,2.发送失败
* Timestamp smstime; //发送时间

* --------------------
*//*
public static String TB_REMIND = "tb_remind";
public static DBCollectionWraper getTbRemind(){
return new DBCollectionWraper(TB_REMIND);
}*/
/**
* 后台线程跟踪表
* id 编号
* needRemoveAfterSuccess
* needRecord
* title
* compId
* uid
* hostId
* startTime Long类型
* endTime Long类型
* status  1.排队中,2.执行中,3.成功, 4.失败, 5.已删除, 6.非正常中止 tb_backtaskrecord_status
* resultMsg 执行结果
* type 分类标识
* data 附加数据,xml序列化后存储
* beanMethod 加调方法,该方法接受一个ThreadContext对象
*/
public static String TB_THREADINFO = "tb_threadinfos";
private static DBCollectionWraper threadDc = null;
public synchronized static DBCollectionWraper getTbThreadInfo(){
if(threadDc == null){
threadDc = new DBCollectionWraper(TB_THREADINFO);
}
return threadDc;
}
/**
* 外链地址
* param String 参数以xml序列化后保存,{}
* url String 实际url地址,不含参数
* endTime Long 到期时间
* uid Long 所有者
* compId Long 企业
* createTime Long 建立时间
* times Integer 请求次数
* lastRequestTime Long 最后请求时间
* lastRequestIp String 最后请求的IP
* compCode
*/
public static String TB_REQUESTDATA = "tb_requestdata";
private static DBCollectionWraper requestdc = null;
public synchronized static DBCollectionWraper getTbRequestData(){
if(requestdc == null){
requestdc = new DBCollectionWraper(TB_REQUESTDATA);
}
return requestdc;
}
/**
* 流程数据存放表
* content 存放的Map序列化后成xml的数据。
* entryId 便于归类与删除
*/
public static String TB_FLOWFORMDATA = "tb_requestdata";
private static DBCollectionWraper TB_FLOWFORMDATA_DC = null;
public synchronized static DBCollectionWraper getTbFormdata(){
if(TB_FLOWFORMDATA_DC == null){
TB_FLOWFORMDATA_DC = new DBCollectionWraper(TB_FLOWFORMDATA);
}
return TB_FLOWFORMDATA_DC;
}


}




package com.tintop.frame.mongo;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;






import java.util.List;








import org.apache.commons.logging.LogFactory;
import org.bson.types.ObjectId;


import com.bsd.directext.helper.PageData;
import com.mongodb.AggregationOutput;
import com.mongodb.BasicDBObject;
import com.mongodb.BasicDBObjectBuilder;
import com.mongodb.CommandResult;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBDecoderFactory;
import com.mongodb.DBEncoder;
import com.mongodb.DBEncoderFactory;
import com.mongodb.DBObject;
import com.mongodb.GroupCommand;
import com.mongodb.MapReduceCommand;
import com.mongodb.MapReduceCommand.OutputType;
import com.mongodb.MapReduceOutput;
import com.mongodb.Mongo;
import com.mongodb.ReadPreference;
import com.mongodb.WriteConcern;
import com.mongodb.WriteResult;
import com.mongodb.util.JSON;


public class DBCollectionWraper{
protected org.apache.commons.logging.Log log = LogFactory.getLog(DBCollectionWraper.class);
//当前mongo
private Mongo mongo;
//数据库
private String db;
//集合
private String dc;
public DBCollectionWraper() {
mongo = MongoDbConUtils.getMongo();
}
public DBCollectionWraper(String name) {
db = "tintopapp";
dc = name;
this.mongo = MongoDbConUtils.getMongo();
}
public DBCollectionWraper(String dbname, String name) {
db = dbname;
dc = name;
this.mongo = MongoDbConUtils.getMongo();
}
public DBCollectionWraper(Mongo mongo, String dbname, String name) {
db = dbname;
dc = name;
this.mongo = mongo;

/**
* 建立队列
* @param dbname
* @param name
* @param spaceSize
* @param maxrec
*/
public DBCollectionWraper(String dbname, String name, long spaceSize, int maxrec) {


this.mongo = MongoDbConUtils.getMongo();
if(maxrec > 0){
if(!mongo.getDB(dbname).collectionExists(name)){
BasicDBObject params = new BasicDBObject();
params.put("capped", true);
params.put("max", maxrec);
params.put("size", spaceSize);
mongo.getDB(dbname).createCollection(name, params);
}
}
this.db = dbname;
this.dc = name;
}
public DBCollection getDc(){
return mongo.getDB(db).getCollection(dc);
}
public DB getDb(){
return mongo.getDB(this.db);
}

/**
* 根据ID获取
*/
public DBObject getById(String id){
return findOne(new BasicDBObject("_id", new ObjectId(id)));
}
/**
* 根据ID更新单个对象
* @param option
*/
public WriteResult update(DBObject obj){
if(obj == null)return null;
return getDc().save(obj);
}

/**
* 根据_id,如果为空则新加,否则更新
* @param obj
* @return
*/
public WriteResult saveOrUpdate(DBObject obj){
if(obj == null)return null;
if(obj.get("_id") == null){
return getDc().save(obj);
}
return update(obj);
}
/**
* 根据ID删除
* @param option
*/
public WriteResult removeById(String id){
return getDc().remove(new BasicDBObject("_id", new ObjectId(id)));
}
/**
* 适用于主键为字符串,不为OBJECTID时
* @param id
* @return
*/
public WriteResult removeByIdStr(String id){
return getDc().remove(new BasicDBObject("_id", id));
}
public PageData findPage(BasicDBObjectBuilder builder, Integer start, Integer limit){
return findPage(builder.get(), start, limit);
}
/**
* 执行分页查询
* @param option
*/
public PageData findPage(DBObject obj, Integer start, Integer limit){
return findPage(obj, null, start, limit);
}
/**
* 执行分页查询
* @param option
*/
public PageData findPage(DBObject obj, DBObject sort, Integer start, Integer limit){
return findPage(obj, sort, null, start, limit);
}
/**
* 执行分页查询
* @param option
*/
public PageData findPage(DBObject obj, DBObject sort, DBObject fields, Integer start, Integer limit){
//log.debug("执行MONGO分页查询:" + obj + ",start:" + start + ",limit:" + limit);
start = (start == null?0:start);
limit = limit==null||limit<=0?20:limit;
DBCursor cur = fields==null?getDc().find(obj):getDc().find(obj, fields);
if(sort != null){
cur.sort(sort);
}
cur.batchSize(limit).skip(start).limit(limit);
int total = cur.count();
List<DBObject> ls = new ArrayList<DBObject>();
PageData pd = new PageData();
while(cur.hasNext()){
ls.add(cur.next());
}
pd.setData(ls);
pd.setPage(start/limit);
pd.setTotal(total);
pd.setPageSize(limit);
return pd;
}
/**
* 获取第一个对象
* @param option
*/
public DBObject findFirst(DBObject ref){
DBCursor cur = this.find(ref);
if(cur.hasNext()){
return cur.next();
}
return null;
}


public void addOption(int option) {
getDc().addOption(option);
}
public AggregationOutput aggregate(DBObject firstOp,
DBObject... additionalOps) {
return getDc().aggregate(firstOp, additionalOps);
}
public Object apply(DBObject jo, boolean ensureID) {
return getDc().apply(jo, ensureID);
}
public Object apply(DBObject o) {
return getDc().apply(o);
}
public long count() {
return getDc().count();
}
public long count(DBObject query, ReadPreference readPrefs) {
return getDc().count(query, readPrefs);
}
public long count(DBObject query) {
return getDc().count(query);
}
public void createIndex(DBObject arg0, DBObject arg1, DBEncoder arg2) {
getDc().createIndex(arg0, arg1, arg2);
}
public void createIndex(DBObject keys, DBObject options) {
getDc().createIndex(keys, options);
}
public void createIndex(DBObject keys) {
getDc().createIndex(keys);
}
public List distinct(String key, DBObject query, ReadPreference readPrefs) {
return getDc().distinct(key, query, readPrefs);
}
public List distinct(String key, DBObject query) {
return getDc().distinct(key, query);
}
public List distinct(String key, ReadPreference readPrefs) {
return getDc().distinct(key, readPrefs);
}
public List distinct(String key) {
return getDc().distinct(key);
}
public void drop() {
getDc().drop();
}
public void dropIndex(DBObject keys) {
getDc().dropIndex(keys);
}
public void dropIndex(String name) {
getDc().dropIndex(name);
}
public void dropIndexes() {
getDc().dropIndexes();
}
public void dropIndexes(String name) {
getDc().dropIndexes(name);
}
public void ensureIndex(DBObject arg0, DBObject arg1) {
getDc().ensureIndex(arg0, arg1);
}
public void ensureIndex(DBObject keys, String name, boolean unique) {
getDc().ensureIndex(keys, name, unique);
}
public void ensureIndex(DBObject keys, String name) {
getDc().ensureIndex(keys, name);
}
public void ensureIndex(DBObject keys) {
getDc().ensureIndex(keys);
}
public void ensureIndex(String name) {
getDc().ensureIndex(name);
}
public DBCursor find() {
return getDc().find();
}
public DBCursor find(DBObject ref, DBObject keys) {
return getDc().find(ref, keys);
}
public DBCursor find(DBObject ref) {
return getDc().find(ref);
}
/**
* 执行查询更新,只更新符合条件的第一条对象
* @param query 查询对象
* @param fields 返回对象的字段,不给定时为所有
* @param sort 排序
* @param remove 是否删除,默认为false
* @param update 更新的内容
* @param newflag 如果更新的field在原field中存在,是否覆盖
* @param upsert 如果记录不存在是为新加
* @return
*/
public DBObject findAndModify(DBObject query, DBObject fields, DBObject sort,
boolean remove, DBObject update, boolean newflag, boolean upsert) {
return getDc().findAndModify(query, fields, sort, remove, update, newflag, upsert);
}
public DBObject findAndModify(DBObject query, DBObject sort, DBObject update) {
return getDc().findAndModify(query, sort, update);
}
public DBObject findAndModify(DBObject query, DBObject update) {
return getDc().findAndModify(query, update);
}
public DBObject findAndModify(DBObject query, String field, Object value) {
BasicDBObject update = new BasicDBObject();
Map<String, Object> rec = new HashMap<String, Object>();
rec.put(field, value);
update.put("$set", rec);
//修改本地缓存
DBObject nobj = getDc().findAndModify(query, update);
if(nobj != null){
nobj.put(field, value);
}
return nobj;
}
public DBObject findAndRemove(DBObject query) {
return getDc().findAndRemove(query);
}
public DBObject findOne() {
return getDc().findOne();
}
public DBObject findOne(DBObject o, DBObject fields, DBObject orderBy,
ReadPreference readPref) {
return getDc().findOne(o, fields, orderBy, readPref);
}
public DBObject findOne(DBObject o, DBObject fields, DBObject orderBy) {
return getDc().findOne(o, fields, orderBy);
}
public DBObject findOne(DBObject o, DBObject fields, ReadPreference readPref) {
return getDc().findOne(o, fields, readPref);
}
public DBObject findOne(DBObject o, DBObject fields) {
return getDc().findOne(o, fields);
}
public DBObject findOne(DBObject o) {
return getDc().findOne(o);
}
public DBObject findOne(Object obj, DBObject fields) {
return getDc().findOne(obj, fields);
}
public DBObject findOne(Object obj) {
return getDc().findOne(obj);
}

public long getCount() {
return getDc().getCount();
}
public long getCount(DBObject arg0, DBObject arg1, long arg2, long arg3,
ReadPreference arg4) {
return getDc().getCount(arg0, arg1, arg2, arg3, arg4);
}
public long getCount(DBObject query, DBObject fields, long limit, long skip) {
return getDc().getCount(query, fields, limit, skip);
}
public long getCount(DBObject query, DBObject fields,
ReadPreference readPrefs) {
return getDc().getCount(query, fields, readPrefs);
}
public long getCount(DBObject query, DBObject fields) {
return getDc().getCount(query, fields);
}
public long getCount(DBObject query) {
return getDc().getCount(query);
}
public long getCount(ReadPreference readPrefs) {
return getDc().getCount(readPrefs);
}
public String getFullName() {
return getDc().getFullName();
}
public List<DBObject> getIndexInfo() {
return getDc().getIndexInfo();
}
public String getName() {
return getDc().getName();
}
public Class getObjectClass() {
return getDc().getObjectClass();
}
public int getOptions() {
return getDc().getOptions();
}
public ReadPreference getReadPreference() {
return getDc().getReadPreference();
}
public CommandResult getStats() {
return getDc().getStats();
}
public WriteConcern getWriteConcern() {
return getDc().getWriteConcern();
}
public DBObject group(DBObject key, DBObject cond, DBObject initial,
String reduce, String finalize, ReadPreference readPrefs) {
return getDc().group(key, cond, initial, reduce, finalize, readPrefs);
}
public DBObject group(DBObject key, DBObject cond, DBObject initial,
String reduce, String finalize) {
return getDc().group(key, cond, initial, reduce, finalize);
}
public DBObject group(DBObject key, DBObject cond, DBObject initial,
String reduce) {
return getDc().group(key, cond, initial, reduce);
}
public DBObject group(GroupCommand cmd, ReadPreference readPrefs) {
return getDc().group(cmd, readPrefs);
}
public DBObject group(GroupCommand cmd) {
return getDc().group(cmd);
}
public WriteResult insert(DBObject o, WriteConcern concern) {
return getDc().insert(o, concern);
}
public WriteResult insert(DBObject... arr) {
return getDc().insert(arr);
}
public WriteResult insert(DBObject[] arg0, WriteConcern arg1, DBEncoder arg2) {
return getDc().insert(arg0, arg1, arg2);
}
public WriteResult insert(DBObject[] arr, WriteConcern concern) {
return getDc().insert(arr, concern);
}
public WriteResult insert(List<DBObject> list, WriteConcern concern) {
return getDc().insert(list, concern);
}
public WriteResult insert(List<DBObject> list) {
return getDc().insert(list);
}
public WriteResult insert(WriteConcern concern, DBObject... arr) {
return getDc().insert(concern, arr);
}
public boolean isCapped() {
return getDc().isCapped();
}
public MapReduceOutput mapReduce(DBObject command) {
return getDc().mapReduce(command);
}
public MapReduceOutput mapReduce(MapReduceCommand command) {
return getDc().mapReduce(command);
}
public MapReduceOutput mapReduce(String map, String reduce,
String outputTarget, DBObject query) {
return getDc().mapReduce(map, reduce, outputTarget, query);
}
public MapReduceOutput mapReduce(String map, String reduce,
String outputTarget, OutputType outputType, DBObject query,
ReadPreference readPrefs) {
return getDc().mapReduce(map, reduce, outputTarget, outputType, query,
readPrefs);
}
public MapReduceOutput mapReduce(String map, String reduce,
String outputTarget, OutputType outputType, DBObject query) {
return getDc().mapReduce(map, reduce, outputTarget, outputType, query);
}
public WriteResult remove(DBObject arg0, WriteConcern arg1, DBEncoder arg2) {
return getDc().remove(arg0, arg1, arg2);
}
public WriteResult remove(DBObject o, WriteConcern concern) {
return getDc().remove(o, concern);
}
public WriteResult remove(DBObject o) {
return getDc().remove(o);
}
public DBCollection rename(String newName, boolean dropTarget) {
return getDc().rename(newName, dropTarget);
}
public DBCollection rename(String newName) {
return getDc().rename(newName);
}
public void resetIndexCache() {
getDc().resetIndexCache();
}
public void resetOptions() {
getDc().resetOptions();
}
public WriteResult save(DBObject jo, WriteConcern concern) {
try {
return getDc().save(jo, concern);
} catch (IllegalArgumentException e) {
jo = (DBObject) JSON.parse(jo.toString());
return getDc().save(jo, concern);
}
}
public WriteResult save(DBObject jo) {
try {
return getDc().save(jo);
} catch (IllegalArgumentException e) {
jo = (DBObject) JSON.parse(jo.toString());
return getDc().save(jo);
}
}
public void setDBDecoderFactory(DBDecoderFactory fact) {
getDc().setDBDecoderFactory(fact);
}
public void setDBEncoderFactory(DBEncoderFactory fact) {
getDc().setDBEncoderFactory(fact);
}
public void setHintFields(List<DBObject> lst) {
getDc().setHintFields(lst);
}
public void setInternalClass(String path, Class c) {
getDc().setInternalClass(path, c);
}
public void setObjectClass(Class c) {
getDc().setObjectClass(c);
}
public void setOptions(int options) {
getDc().setOptions(options);
}
public void setReadPreference(ReadPreference preference) {
getDc().setReadPreference(preference);
}
public void setWriteConcern(WriteConcern concern) {
getDc().setWriteConcern(concern);
}
public WriteResult update(DBObject arg0, DBObject arg1, boolean arg2,
boolean arg3, WriteConcern arg4, DBEncoder arg5) {
return getDc().update(arg0, arg1, arg2, arg3, arg4, arg5);
}
public WriteResult update(DBObject q, DBObject o, boolean upsert,
boolean multi, WriteConcern concern) {
return getDc().update(q, o, upsert, multi, concern);
}
/**

* @param q
* @param o
* @param upsert 如果未找到时是否插入 默认为false
* @param multi 是否全部更新,默认为false
* @return
*/
public WriteResult update(DBObject q, DBObject o, boolean upsert,
boolean multi) {
try {
return getDc().update(q, o, upsert, multi);
} catch (IllegalArgumentException e) {
o = (DBObject) JSON.parse(o.toString());
return getDc().update(q, o, upsert, multi);
}
}
public WriteResult update(DBObject q, DBObject o) {
try {
return getDc().update(q, o);
} catch (IllegalArgumentException e) {
o = (DBObject) JSON.parse(o.toString());
return getDc().update(q, o);
}
}
public WriteResult updateMulti(DBObject q, DBObject o) {
try {
return getDc().updateMulti(q, o);
} catch (IllegalArgumentException e) {
o = (DBObject) JSON.parse(o.toString());
return getDc().updateMulti(q, o);
}
}
/**
* 批量更新
*/
public WriteResult batchUpdate(DBObject query, String filed, Object value){
BasicDBObject update = new BasicDBObject();
Map<String, Object> data = new HashMap<String, Object>();
data.put(filed, value);
update.put("$set", data);
return getDc().updateMulti(query, update);
}
/**
* 如果_id不是ObjectId时使用
* @param idy
* @return
*/
public DBObject getByIdStr(String id) {
return getDc().findOne(new BasicDBObject("_id", id));
}
/**
* 使用$set更新
* @param obj
* @param upobj
*/
public void updateWithSet(DBObject obj, BasicDBObject upobj) {
getDc().update(obj, new BasicDBObject("$set", upobj));
}
public Mongo getMongo() {
return mongo;
}
}


宝塔面板是一款集成多种服务器管理功能的开源面板,而MongoDB则是一款流行的NoSQL数据库系统。在宝塔面板,可以通过简单的操作来安装、配置和管理MongoDB数据库。 首先,我们需要登录到宝塔面板的管理后台。在面板左侧的列表找到“软件”选项,并点击进入。着,在软件列表找到MongoDB,并点击右侧的“安装”按钮。 安装MongoDB时,我们可以选择版本号和安装路径。通常情况下,宝塔面板会自动选择最新的稳定版本进行安装,同时也会提供MongoDB的安装目录建议。 安装完成后,在软件列表会显示MongoDB的安装状态。点击右侧的“管理”按钮,就可以进入MongoDB的管理界面。 在MongoDB的管理界面,可以进行多项配置和管理操作。我们可以创建新的数据库,设置用户名和密码进行数据库认证,导入和导出数据,以及查看和监控数据库的运行状态。 在宝塔面板管理MongoDB,还可以实现一些高级功能。例如,可以设置数据库的备份和恢复策略,定时进行备份或手动创建备份文件,以确保数据的安全性。同时,还可以配置数据库的性能参数,对数据库进行优化,提高数据库的访问速度和响应能力。 总之,宝塔面板为用户提供了简单快捷的方式来安装、配置和管理MongoDB数据库。通过宝塔面板,我们可以轻松地进行数据库的各项操作,提高开发和管理的效率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值