【发布时间】:2021-03-04 13:10:47
【问题描述】:
{
"_id": {
"$oid": "5f244a0c9b20935b3bdc2cd9"
},
"user": {
"rid": "5f12ba968ca0084ee7f7ea9b",
"name": "",
"phone": “0123456789”
},
"clazz": “Test”,
"enrolment_history": [{
"_id": {
"$oid": "5f245e2f1906715c9e52d675"
},
"start_from": {
"$date": "2020-06-30T18:30:00.000Z"
},
"expires_in": {
"$date": "2020-07-31T18:30:00.000Z"
},
"enrollment_date": {
"$date": "2020-06-30T18:30:00.000Z"
},
"payment_method": "Free",
"status": "SUCCESS",
"clazz_transaction": "5f3e74f8d26e962003103c11",
"month": "2020-6"
}, {
"_id": {
"$oid": "5f3e790c1e3c741f9eb6e53b"
},
"start_from": {
"$date": "2020-07-31T18:30:00.000Z"
},
"expires_in": {
"$date": "2020-08-31T18:30:00.000Z"
},
"enrollment_date": {
"$date": "2020-07-31T18:30:00.000Z"
},
"payment_method": "Free",
"status": "SUCCESS",
"clazz_transaction": "5f3e790c1e3c741f9eb6e53a",
"month": "2020-7"
}, {
"_id": {
"$oid": "5f5763bfc2464554c15a2b28"
},
"start_from": {
"$date": "2020-08-31T18:30:00.000Z"
},
"expires_in": {
"$date": "2020-09-30T18:30:00.000Z"
},
"enrollment_date": {
"$date": "2020-09-08T10:58:07.333Z"
},
"payment_method": "Free",
"status": "SUCCESS",
"clazz_transaction": "5f5763bfc2464554c15a2b27",
"month": "2020-8"
}
}
我有那种文档列表,所以我需要使用下面的过滤器来获取这个文档
{"phone":"0123456789","enrolment_history.month":"2020-6"}
输出 => (删除 enrolment_history 数组中的其他数据)
{
"_id": {
"$oid": "5f244a0c9b20935b3bdc2cd9"
},
"user": {
"rid": "5f12ba968ca0084ee7f7ea9b",
"name": "",
"phone": “0123456789”
},
"clazz": “Test”,
"enrolment_history": [{
"_id": {
"$oid": "5f245e2f1906715c9e52d675"
},
"start_from": {
"$date": "2020-06-30T18:30:00.000Z"
},
"expires_in": {
"$date": "2020-07-31T18:30:00.000Z"
},
"enrollment_date": {
"$date": "2020-06-30T18:30:00.000Z"
},
"payment_method": "Free",
"status": "SUCCESS",
"clazz_transaction": "5f3e74f8d26e962003103c11",
"month": "2020-6"
}
}
【问题讨论】: