========================================================
mongo查询:
1 日期查询(data)
db.getCollection('webLog').find({content: /主机重置/, "createTime" : { "$gte" :new ISODate("2020-12-01 08:32:44.342Z"), "$lte" : new ISODate("2020-12-24 08:32:44.342Z")}}).sort({createTime:-1}).limit(5000);
2 模糊查询/主机重置/ == %主机重置%
db.getCollection('webLog').find({content: /主机重置/}).sort({createTime:-1})
======================================================
1 查询一段时间的数据
{ "createTime" : { "$gte" : NumberLong("1536233690"), "$lte" : NumberLong("1536233690") }}
db.LBInfoMonitor.find({ "create_time" : { "$gte" : NumberLong("1510888200013"), "$lte" : NumberLong("1510888260019") } }).limit(50);
db.LBInfoMonitor.find({ "create_time" : { "$gte" : NumberLong("1510888200013"), "$lte" : NumberLong("1510888260019") } }).limit(50).explain();
2 in 查询:
{'host_name':{$in:['8392210','4zvqk']}}
{'arrow_uuid':{$in:['8392218','8392218']}, 'handled' : '0'}
==================================================================================================
3系统日志:http://boss.pppcloud.cn/smartBus-Manager-v1/systemLogs?&limit=10
package com.xinnet.cloud.log;LogController
用到mongoDB
find / -name mongodb
/usr/local/mongodb
//查看端口号
netstat -nutlp
//操作mongo数据库
ps -ef|grep mongodb
mongo -port 27010
show dbs
use smart
db.local.insert({"name":"菜鸟教程"});
db.local.find();
db.smart.insert({"name":"菜鸟教程"})
db.smart.find().pretty()
db.smart.remove({"name":"菜鸟教程"})
===========================================================================
//查看mongo中的数据
LBInfoMonitor
MonitorDaoImpl
public List<VmStatInfoVO> queryVmStatInfos(String vid, Long startCreateTime, Long endCreateTime, int limit) {
// DBCollection collection = createVmStatCollection();
// DBObject queryCondition = new BasicDBObject();
// queryCondition.put(MongoFields.VM_INFO_STAT_CREATE_TIME, new BasicDBObject("$gte", startCreateTime).append("$lte", endCreateTime));
// queryCondition.put(MongoFields.VM_INFO_STAT_VID, vid);
// DBCursor cursor = collection.find(queryCondition).sort(new BasicDBObject(MongoFields.VM_INFO_STAT_CREATE_TIME, 1));
// if (limit > 0) {
// cursor.limit(limit);
// }
// List<DBObject> vmStatInofs = new ArrayList<DBObject>();
// while (cursor.hasNext()) {
// vmStatInofs.add(cursor.next());
// }
Query query = new Query();
query.addCriteria(Criteria.where(MongoFields.VM_INFO_STAT_VID).is(vid.toString()));
query.addCriteria(Criteria.where(MongoFields.VM_INFO_STAT_CREATE_TIME).gte(startCreateTime).lte(endCreateTime));
query.with(new Sort(Sort.Direction.ASC, MongoFields.VM_INFO_STAT_CREATE_TIME));
List<VmStatInfoVO> vmStatInfoVos = mongoTemplate.find(query, VmStatInfoVO.class, MongoKeys.VM_INFO_STAT_MONITOR);
return vmStatInfoVos;
}
MonitorDaoImpl
/**
* 向mongodb中插入主机监控信息
* @author wanghongyu
* @date 2015年8月11日 下午12:44:22
* @param hostInfos void
*/
public void addHostInfosWithMap(List<Map<String, Object>> hostInfos) {
if (hostInfos != null && hostInfos.size() > 0) {
for (Map<String, Object> hostInfo : hostInfos) {
HostInfoVOMongo bean = UJson.toObject(UJson.toString(hostInfo), HostInfoVOMongo.class);
bean.setRecord(DATETIME_FORMAT.format(Calendar.getInstance()));
bean.setId(null);
mongoTemplate.insert(bean, MongoKeys.HOST_INFO_MONITOR);
}
// DBCollection hostCollection = createHostCollection();
// for (Map<String, Object> hostInfo : hostInfos) {
// hostCollection.insert(convert(hostInfo));
// }
}
}