SequoiaDB 简介						 
					
						快速入门						 
					
						安装部署						 
					
						数据库实例						 
					
						分布式引擎						 
					
						SAC 管控中心						 
					
						SequoiaPerf 性能分析工具						 
					
						参考手册						 
					
						常见问题及解答(FAQ)						 
					
						版本信息						 
					
{ <字段名>: { $substr: <值> } }
返回字符串的子串,原始值为数组类型时对每个数组元素执行该操作,非字符串类型返回 null 。
find({},{<fieldName>:{<$substr:[Pos,Len]>}})
find({},{<fieldName>:{<$substr:Value>}})
在集合 sample.employee 插入如下记录:
> db.sample.employee.insert( { "a": "abcdefg" } )
作为选择符使用
返回下标为 0,长度为 2 的子串
> db.sample.employee.find( {}, { "a": { "$substr": 2 } } )
{
  "_id": {
    "$oid": "58257afbec5c9b3b7e000002"
  },
  "a": "ab"
}
Return 1 row(s).
返回倒数第二个字符开始的子串
> db.sample.employee.find( {}, { "a": { "$substr": -2 } } )
{
  "_id": {
    "$oid": "58257afbec5c9b3b7e000002"
  },
  "a": "fg"
}
Return 1 row(s).
返回下标为 2,长度为 3 的子串
> db.sample.employee.find( {}, { "a": { "$substr": [ 2, 3 ] } } )
{
  "_id": {
    "$oid": "58257afbec5c9b3b7e000002"
  },
  "a": "cde"
}
Return 1 row(s).
返回倒数第二个字符开始,长度为 3 的子串
> db.sample.employee.find( {}, { "a": { "$substr": [ -2, 3 ] } } )
{
  "_id": {
    "$oid": "58257afbec5c9b3b7e000002"
  },
  "a": "fg"
}
Return 1 row(s).
Note:
子串长度不足3。
与匹配符配合使用
匹配字段 a 下标为 2,长度为 3 的子串为“cde”的记录
> db.sample.employee.find( { "a": { "$substr": [ 2, 3 ], "$et": "cde" } } )
{
  "_id": {
    "$oid": "58257afbec5c9b3b7e000002"
  },
  "a": "abcdefg"
}
Return 1 row(s). 展开
            展开
          
   
   
   
   
   
   
   
