私信  •  关注

Fumiya Karasawa

Fumiya Karasawa 最近创建的主题
Fumiya Karasawa 最近回复了
4 年前
回复了 Fumiya Karasawa 创建的主题 » mongodb中的条件更新多?[副本]

查询 $where $expr

$regex , $出口 .

db.usercollection.find({ 
  "name": /^[\s\S]{40,}$/, // name.length >= 40
})

or 

db.usercollection.find({ 
  "name": { "$regex": "^[\s\S]{40,}$" }, // name.length >= 40
})

此查询的含义与

db.usercollection.find({ 
  "$where": "this.name && this.name.length >= 40",
})

or

db.usercollection.find({ 
    "name": { "$exists": true },
    "$expr": { "$gte": [ { "$strLenCP": "$name" }, 40 ] } 
})

# find
$where: 10529.359ms
$expr: 5305.801ms
$regex: 2516.124ms

# count
$where: 10872.006ms
$expr: 2630.155ms
$regex: 158.066ms