mogodb用法汇总
等于用法:
db.getCollection('t_xxx').find({"字段A": "A"}).limit(100)
in用法:
db.getCollection('t_xxx').find({"字段A": {$in:["A0","A1"]}}).limit(100)
notin用法
db.getCollection('t_xxx').find({ 字段A: { $nin: ["A1", "A2"] } })
分页查询用法:
b.getCollection('t_xxx').find({字段A: {$gt: "A1"}}).sort({字段A: 1}).limit(100)
and和NumberDecimal用法:
db.getCollection('t_xxx').find({$and: [{字段A:{$gt:"A1"},字段B:{$gt:NumberDecimal("0"),$lt:NumberDecimal("10")}}]}).sort({字段A: 1}).limit(100)
不等于用法:
db.getCollection('t_xxx').find({$and: [{字段A:{$gt:"A1"},字段B:{$ne:NumberDecimal("0")}}]}).sort({字段A: 1}).limit(100)
字段不为空用法
db.getCollection('t_xxx').find({ 字段A: { $ne: null, $exists: true } })
查询只返回某个几个字段
db.getCollection('t_xxx').aggregate([
{
$match: {
"keyInfo.acctNo": "MOCK430071012"
}
},
{
$project: {
tradeType: 1,
result: 1
}
}
])
索引操作
db.getCollection('xxx').dropIndex("x_1")
db.getCollection('xxx').createIndex({ x: 1 },{background:true});
db.getCollection('xxx').getIndexes()
插入一条数据:
db.getCollection('t_sod_crypto_position_2023-07-06').insertOne([
{ }
])