来自" How to update collection and increment hours for ISO date"。
似乎RoboMongo无法使用数组过滤器执行查询:
同样的查询,如果在通过Mongo shell执行时查找:
> db.collection.update({
... "results.score": {
... "$exists": true
... }
... }, {
... "$mul": {
... "results.$[result].score": 10
... }
... }, {
... "arrayFilters": [{
... "result.score": {
... "$exists": true
... }
... }],
... "multi": true
... })
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
查看Mongo服务器中的日志记录,看起来查询是否正确传递,但仍然失败:
D COMMAND [conn4] run command test.$cmd { update: "collection", updates: [ { q: { results.score: { $exists: true } }, u: { $mul: { results.$[result].score: 10.0 } }, multi: true, upsert: false } ], ordered: true, $db: "test" }
D - [conn4] User Assertion: 2:No array filter found for identifier 'result' in path 'results.$[result].score' src\mongo\db\update\update_driver.cpp 132
D WRITE [conn4] Caught Assertion in update: BadValue: No array filter found for identifier 'result' in path 'results.$[result].score'
I WRITE [conn4] update test.collection appName: "MongoDB Shell" command: { q: { results.score: { $exists: true } }, u: { $mul: { results.$[result].score: 10.0 } }, multi: true, upsert: false } exception: No array filter found for identifier 'result' in path 'results.$[result].score' code:BadValue numYields:0 locks:{} 4ms
D REPL [conn4] Waiting for write concern. OpTime: { ts: Timestamp(0, 0), t: -1 }, write concern: { w: 1, wtimeout: 0 }
I COMMAND [conn4] command test.$cmd appName: "MongoDB Shell" command: update { update: "collection", updates: [ { q: { results.score: { $exists: true } }, u: { $mul: { results.$[result].score: 10.0 } }, multi: true, upsert: false } ], ordered: true, $db: "test" } numYields:0 reslen:183 locks:{} protocol:op_command 7ms
D COMMAND [conn4] run command test.$cmd { getlasterror: 1.0, w: 1.0, $readPreference: { mode: "secondaryPreferred" }, $db: "test" }
I COMMAND [conn4] command test.$cmd appName: "MongoDB Shell" command: getLastError { getlasterror: 1.0, w: 1.0, $readPreference: { mode: "secondaryPreferred" }, $db: "test" } numYields:0 reslen:169 locks:{} protocol:op_command 0ms
来自shell的日志不同:
D COMMAND [conn8] run command test.$cmd { update: "collection", ordered: true, $db: "test" }
D STORAGE [conn8] NamespaceUUIDCache: registered namespace test.collection with UUID a5f7f2ef-a7e3-4189-a9c4-29fdb5a18db9
D QUERY [conn8] Only one plan is available; it will be run but will not be cached. query: { results.score: { $exists: true } } sort: {} projection: {}, planSummary: COLLSCAN
D STORAGE [conn8] WT begin_transaction for snapshot id 367
D STORAGE [conn8] WT commit_transaction for snapshot id 367
D STORAGE [conn8] WT begin_transaction for snapshot id 368
D STORAGE [conn8] WT rollback_transaction for snapshot id 368
I WRITE [conn8] update test.collection appName: "MongoDB Shell" command: { q: { results.score: { $exists: true } }, u: { $mul: { results.$[result].score: 10.0 } }, arrayFilters: [ { result.score: { $exists: true } } ], multi: true, upsert: false } planSummary: COLLSCAN keysExamined:0 docsExamined:1 nMatched:1 nModified:1 numYields:0 locks:{ Global: { acquireCount: { r: 1, w: 1 } }, Database: { acquireCount: { w: 1 } }, Collection: { acquireCount: { w: 1 } } } 3ms
D REPL [conn8] Waiting for write concern. OpTime: { ts: Timestamp(0, 0), t: -1 }, write concern: { w: 1, wtimeout: 0 }
I COMMAND [conn8] command test.$cmd appName: "MongoDB Shell" command: update { update: "collection", ordered: true, $db: "test" } numYields:0 reslen:44 locks:{ Global: { acquireCount: { r: 1, w: 1 } }, Database: { acquireCount: { w: 1 } }, Collection: { acquireCount: { w: 1 } } } protocol:op_msg 4ms
D COMMAND [conn8] run command test.$cmd { isMaster: 1.0, forShell: 1.0, $db: "test" }
D NETWORK [conn8] Starting server-side compression negotiation
D NETWORK [conn8] Compression negotiation not requested by client
I COMMAND [conn8] command test.$cmd appName: "MongoDB Shell" command: isMaster { isMaster: 1.0, forShell: 1.0, $db: "test" } numYields:0 reslen:208 locks:{} protocol:op_msg 1ms
我无法看到任何暗示某些事情出错的事情(当然,除了断言失败)。