使用 pymongo 根据字段长度检索 MongoDB 文档
Retrieve MongoDB document based on field length using pymongo
我有一个格式如下的文档,
{
"_id" : ObjectId("54a2462820fb5b6068b45b05"),
"Ref":1,
"a" : {
"b" : "value1",
"c" : "value2",
"d" : {
"e" : "value3"
}
}
}
我需要检索长度 "e" 大于 5 的文档。
使用 '$where' 运算符来使用 javascript 并比较字符串长度。
db.myCollection.find({'$where':'this.a.e.length > 5'})
我有一个格式如下的文档,
{
"_id" : ObjectId("54a2462820fb5b6068b45b05"),
"Ref":1,
"a" : {
"b" : "value1",
"c" : "value2",
"d" : {
"e" : "value3"
}
}
}
我需要检索长度 "e" 大于 5 的文档。
使用 '$where' 运算符来使用 javascript 并比较字符串长度。
db.myCollection.find({'$where':'this.a.e.length > 5'})