mysql and mongo 导出数据语句
将符合查询条件的数据导出到account_name的表中
mysql -uupsmart -p -dtal1229 -e "select account,account_name from account;" account_name
-d 在我电脑上不能执行, 改为-D 代表数据库
mysql -uupsmart -p -Dtal1229 -e "select account,account_name from account;" account_name
将mongo库中的数据导出
mongoexport -h ress02-idc14 -d tal20180321 -c sysRequestWrapper --csv -f "account,uri,requestTime,totalPrice,isFee" -q '{isFee:1,requestTime:{$gte:ISODate("2018-06-01T00:00:00.000Z"),$lt:ISODate("2018-06-16T00:00:00.000Z")}}' -o tal_fee_detail_201806_01.csv
–csv 在我的电脑上不能执行 改为–type=csv
说明:
-h:数据库宿主机的IP
-u:数据库用户名
-p:数据库密码
-d:数据库名字
-c:集合的名字
-f:导出的列名
-q:导出数据的过滤条件
–csv:导出格式为csv
$gt -------- greater than >
$gte --------- gt equal >=
$lt -------- less than <
$lte --------- lt equal <=
$ne ----------- not equal !=
$eq -------- equal =
MongoDB查询如何只输出部分字段内容
MongoDB 查询数据的语法格式如下:
db.collection.find(query, projection)
如果没有指定projection,find()方法返回所有匹配文档的所有字段。
可以指定要包含的字段(例如: {field:1})或者指定要排除的字段(例如:{field:0})。
默认_id是包含在结果集合中的,要从结果集中排除_id字段,需要在 projection中指定排除_id字段({_id:0})
只输出cards字段 会默认增加_id字段
db.sys_request_info.find({“cards”: {$in: [‘2F1078782BC405CD7EC81444B6EDBF5CA91DEA83E2E15C1C87ED984D36AE6EEF’,‘46F5202B40E64307CEEBDDE2A0AD2F11F9DA26CD20C2EEA6E1CF0876520CBC54’]},“path”:"/quota/personals"},{“cards”:1})
sort命令 按时间排查处最新数据
db.sys_request_info.find({"account":"F1130004","path":"/quota/personal","request_time":{$gte:ISODate("2018-06-30T16:00:00.000Z"),$lte:ISODate("2018-07-31T16:00:00.000Z")}}).sort({"request_time":-1}).limit(5)
count命令
db.getCollection('sys_request_info').find({"account":"TXYZH001","path":"/quota/personals","cards":{ $size: 5 }}).count()
是否存在
cards为数组 数组的第六个元素是否存在
db.getCollection('sys_request_info').count({"account":"TXYZH001","path":"/quota/personals", "cards.6": {$exists:1}})
mongo模糊查询查询“//”包含的内容
db.sys_request_info.find({“request_header.host” : /192.168.87.200/})