我正在调试使用flask_pymongo的代码
我看到这段代码
dabb = mongo.db.tbl.find({
"transactions": {'$elemMatch': {"from":{'$elemMatch':{"from":str(to)}},"to":{'$elemMatch':{"to":str(frm)}}}}
},{"transactions.$": 1 })
Run Code Online (Sandbox Code Playgroud)
我不明白 {"transactions.$": 1 } 是做什么的。
它限制数组的内容返回:
dabb = mongo.db.tbl.find({
"transactions": {
'$elemMatch': {
"from":{
'$elemMatch':{ "from":str(to) }
},
"to": {
'$elemMatch':{"to":str(frm)}
}
}
} // Only apply for first element then meet query condition within an array
}, // when a element meet the query condition
{"transactions.$": 1 }) // it will only return that element from array
Run Code Online (Sandbox Code Playgroud)
在获取转换数组中满足查询条件的第一个元素后,它将返回该元素。请参阅包含大量示例的文档
对于您的情况,此链接更合适:
| 归档时间: |
|
| 查看次数: |
2916 次 |
| 最近记录: |