Mongo 将数组列分多个文档(显示对象集合中某一个字段)
db.app_history_submit.aggregate([
{ "$match" : { "orderNo" :"xxx"} },
{ "$match" : { "version" : 1 } },
{ "$unwind" : "$submitParam.loanDetails" },
{ "$match" : { "submitParam.loanDetails.prtSubType" : "01" } },
{ "$project" : {
"submitParam.loanDetails.prtType" : 1,
"submitParam.loanDetails.prtSubType":1,
"submitParam.firstSubmitInfo.firstLoanAmt":1,
"submitParam.firstSubmitInfo.firstLnterms":1,
"submitParam.firstSubmitInfo.firstDownpay":1,
"submitParam.firstSubmitInfo.firstDparato":1,
"submitParam.firstSubmitInfo.firstBalancepay":1,
"submitParam.firstSubmitInfo.firstBalanceto":1 } }
])
非mongo2.6版本之后版本可以使用
db.app_history_submit.find({"orderNo":"xxx","version":1,"submitParam.loanDetails":{$elemMatch:{"prtSubType":"01"}}},{"submitParam.loanDetails":{$elemMatch:{"prtSubType":"01"}}}) .projection( { "submitParam.loanDetails.prtType":1, "submitParam.loanDetails.prtSubType":1, "submitParam.firstSubmitInfo.firstLoanAmt":1, "submitParam.firstSubmitInfo.firstLnterms":1, "submitParam.firstSubmitInfo.firstDownpay":1, "submitParam.firstSubmitInfo.firstDparato":1, "submitParam.firstSubmitInfo.firstBalancepay":1, "submitParam.firstSubmitInfo.firstBalanceto":1 } );
效果
努力提高自己的技术,不忘初心