MongoDB常用指令整理
1 查看集合的條數
db.httpRequestLog.count();
2 and查詢
{$and:[{"requestUrl":"/sleep_reports/pad/report/upload"},{"requestParam.ring_sn":"P11E12210000035"}]}
3 or查詢
{$or:[{"requestParam.ring_sn":"P11E12210000035"},{"requestParam.ring_sn":"P11E12210000036"}]}
in查詢
{"zyzd":{$in:["胃痛"]}}
4 索引操作
創建索引:db.httpRequestServiceLog.ensureIndex({"createTime": 1},{expireAfterSeconds: 2592000});
查看索引:db.httpRequestLog.getIndexes();
刪除索引:db.httpRequestLog.dropIndex("createTime");
5 更新字段為另一個字段的值
db.patient.find({}).forEach( function(item){ db.patient.update({"_id":item._id},{$set:{'shenfenzheng':item.cardId}},false,false); } );
db.serverExceptionLog.update({"status":1},{$set:{"status":2}},false,true);
mongodb中表名稱有中劃線時,使用下面方式處理:
db["my-collection"].find()
業務需求變更永無休止,技術前進就永無止境!

浙公網安備 33010602011771號