基础查询
db.getCollection("hisDetail_newdate").find({"MERC_ID":"826148551378003","AC_DT":{$gte:"20190301"}}).sort({"CHAN_SEQ_NO":-1})
or / and 联合查询
db.getCollection("hisDetail_newdate").find({
$or: [{
$and: [{
"CHAN_SEQ_NO": "000031",
"CHAN_DT": "0518"
}]
}, {
"AC_DT": "20180518"
}]
})
$gte / $ lte (>= and <=)
$gt / $lt (> and <)
db.getCollection("hisDetail_newdate").find({
"MERC_ID": "826148551378003",
"AC_DT": {
$gte: "20190401",
$lte: "20190430"
}
}).sort({ // -1 倒序 ,1 正序
"SORT_ID": - 1
}).limit(10) // 现在行数
同时设置多个字段排序 -1倒序,1正序
db.getCollection("hisDetail_newdate").find({
"AC_DT": {
$gte: "20190401",
$lte: "20190430"
},
"TERM_NO": "66000295",
"MERC_ID": "826440397038005"
}).sort({"AC_DT": - 1, "SORT_ID": - 1})
$or 或
db.getCollection("ORDERBUSINESSDETAIL").find({
$or: [{
"SORT_ID": ""
}, {
"SORT_ID": null
}]
}).sort({
"SORT_ID": - 1
})
$in 包含
db.getCollection("ORDERBUSINESSDETAIL").find({
"PAYGATE_BUSISN": {
$in: [
"P3131905240005832132",
"P3131905240005831986"
]
}
})
$nin 不包含
db.getCollection("ORDERBUSINESSDETAIL").find({
"PAYGATE_BUSISN": {
$nin: [
"P3131905240005832132",
"P3131905240005831986"
]
}
})
$ne 不等于
db.getCollection("ORDERBUSINESSDETAIL").find({
"PAYGATE_BUSISN": {
$ne: "P3131905240005832132"
}
})
$eq 等于
db.getCollection("ORDERBUSINESSDETAIL").find({
"PAYGATE_BUSISN": {
$eq: "P3131905240005832132"
}
})
等同于
db.getCollection("ORDERBUSINESSDETAIL").find({
"PAYGATE_BUSISN": "P3131905240005832132"
})