我有一个包含许多类似结构化文档的集合,两个文档看起来像
输入:
{
"_id": ObjectId("525c22348771ebd7b179add8"),
"cust_id": "A1234",
"score": 500,
"status": "A"
"clear": "No"
}
{
"_id": ObjectId("525c22348771ebd7b179add9"),
"cust_id": "A1234",
"score": 1600,
"status": "B"
"clear": "No"
}
Run Code Online (Sandbox Code Playgroud)
默认情况下clear,所有文档都是"No",
要求:我必须添加所有文件的分数cust_id,只要它们属于status "A"和status "B".如果score超过2000那么我必须更新所有文档的clear属性"Yes"相同cust_id.
预期产量:
{
"_id": ObjectId("525c22348771ebd7b179add8"),
"cust_id": "A1234",
"score": 500,
"status": "A"
"clear": "Yes"
}
{
"_id": ObjectId("525c22348771ebd7b179add9"),
"cust_id": "A1234",
"score": 1600,
"status": "B"
"clear": "Yes"
}
Run Code Online (Sandbox Code Playgroud)
是的,因为1600 + 500 = 2100,2100> …
mongodb ×1