| 拼接 | { $concat: ["$firstName", "-", "$lastName"] } |
|---|---|
| 拆分 | { $split: ["$path", "/"] } |
| 正则判断 | { $regexMatch: { input: "$sku", regex: "^A-" } } |
示例
示例
db.products.aggregate([
{ $addFields: { shortName: { $substrCP: ["$name", 0, 4] }, isA: { $regexMatch: { input: "$sku", regex: "^A-" } } } },
{ $match: { isA: true } }
])$substrCP 按码点截取,中文等多字节字符不会截断错误(区别于按字节的 $substrBytes)。