在我的 mongodb 更改流中获取 'Unrecognized expression '$or''/ "Unknown top level operator $or"
Getting 'Unrecognized expression '$or''/ "Unknown top level operator $or" in my mongodb change streams
所以下面的代码在本地运行,没有出现这个错误。但是,当我使用以下代码部署到 heroku 时:
const profPipeLine = [
{
'$match': {
'$expr': {
'$or:': [
{'$eq': ['operationType', 'insert']},
{'$eq': ['operationType', 'update']},
{'$eq': ['operationType', 'delete']}
]
}
}
}
];
const options = { 'fullDocument': 'updateLookup' };
const profileStream = MatchProfile.watch(profPipeLine, options);
profileStream.on('change', next => {
....
})
我收到这个错误:
2020-12-09T16:22:24.955884+00:00 app[worker.1]: events.js:291
2020-12-09T16:22:24.955886+00:00 app[worker.1]: throw er; // Unhandled 'error' event
2020-12-09T16:22:24.955886+00:00 app[worker.1]: ^
2020-12-09T16:22:24.955887+00:00 app[worker.1]:
2020-12-09T16:22:24.955887+00:00 app[worker.1]: MongoError: Unrecognized expression '$or:'
2020-12-09T16:22:24.955888+00:00 app[worker.1]: at MessageStream.messageHandler (/app/node_modules/mongodb/lib/cmap/connection.js:268:20)
2020-12-09T16:22:24.955888+00:00 app[worker.1]: at MessageStream.emit (events.js:314:20)
2020-12-09T16:22:24.955889+00:00 app[worker.1]: at processIncomingData (/app/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
2020-12-09T16:22:24.955889+00:00 app[worker.1]: at MessageStream._write (/app/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
2020-12-09T16:22:24.955889+00:00 app[worker.1]: at doWrite (_stream_writable.js:403:12)
2020-12-09T16:22:24.955890+00:00 app[worker.1]: at writeOrBuffer (_stream_writable.js:387:5)
2020-12-09T16:22:24.955891+00:00 app[worker.1]: at MessageStream.Writable.write (_stream_writable.js:318:11)
2020-12-09T16:22:24.955891+00:00 app[worker.1]: at TLSSocket.ondata (_stream_readable.js:718:22)
2020-12-09T16:22:24.955891+00:00 app[worker.1]: at TLSSocket.emit (events.js:314:20)
2020-12-09T16:22:24.955892+00:00 app[worker.1]: at addChunk (_stream_readable.js:297:12)
2020-12-09T16:22:24.955892+00:00 app[worker.1]: at readableAddChunk (_stream_readable.js:272:9)
2020-12-09T16:22:24.955893+00:00 app[worker.1]: at TLSSocket.Readable.push (_stream_readable.js:213:10)
2020-12-09T16:22:24.955893+00:00 app[worker.1]: at TLSWrap.onStreamRead (internal/stream_base_commons.js:188:23)
2020-12-09T16:22:24.955894+00:00 app[worker.1]: Emitted 'error' event on ChangeStream instance at:
2020-12-09T16:22:24.955894+00:00 app[worker.1]: at ChangeStream.<anonymous> (/app/node_modules/mongoose/lib/cursor/ChangeStream.js:41:51)
2020-12-09T16:22:24.955898+00:00 app[worker.1]: at ChangeStream.emit (events.js:314:20)
2020-12-09T16:22:24.955899+00:00 app[worker.1]: at processError (/app/node_modules/mongodb/lib/change_stream.js:571:38)
2020-12-09T16:22:24.955899+00:00 app[worker.1]: at ChangeStreamCursor.<anonymous> (/app/node_modules/mongodb/lib/change_stream.js:435:5)
2020-12-09T16:22:24.955900+00:00 app[worker.1]: at ChangeStreamCursor.emit (events.js:314:20)
2020-12-09T16:22:24.955900+00:00 app[worker.1]: at /app/node_modules/mongodb/lib/core/cursor.js:343:16
2020-12-09T16:22:24.955900+00:00 app[worker.1]: at /app/node_modules/mongodb/lib/core/cursor.js:736:9
2020-12-09T16:22:24.955901+00:00 app[worker.1]: at /app/node_modules/mongodb/lib/change_stream.js:329:9
2020-12-09T16:22:24.955901+00:00 app[worker.1]: at done (/app/node_modules/mongodb/lib/core/cursor.js:458:7)
2020-12-09T16:22:24.955902+00:00 app[worker.1]: at /app/node_modules/mongodb/lib/core/cursor.js:533:11
2020-12-09T16:22:24.955902+00:00 app[worker.1]: at executeCallback (/app/node_modules/mongodb/lib/operations/execute_operation.js:70:5)
2020-12-09T16:22:24.955902+00:00 app[worker.1]: at callbackWithRetry (/app/node_modules/mongodb/lib/operations/execute_operation.js:122:14)
2020-12-09T16:22:24.955903+00:00 app[worker.1]: at /app/node_modules/mongodb/lib/operations/command_v2.js:86:9
2020-12-09T16:22:24.955903+00:00 app[worker.1]: at /app/node_modules/mongodb/lib/cmap/connection_pool.js:348:13
2020-12-09T16:22:24.955904+00:00 app[worker.1]: at handleOperationResult (/app/node_modules/mongodb/lib/core/sdam/server.js:558:5)
2020-12-09T16:22:24.955904+00:00 app[worker.1]: at MessageStream.messageHandler (/app/node_modules/mongodb/lib/cmap/connection.js:268:11) {
2020-12-09T16:22:24.955904+00:00 app[worker.1]: operationTime: Timestamp { _bsontype: 'Timestamp', low_: 4, high_: 1607530944 },
2020-12-09T16:22:24.955905+00:00 app[worker.1]: ok: 0,
2020-12-09T16:22:24.955905+00:00 app[worker.1]: code: 168,
2020-12-09T16:22:24.955905+00:00 app[worker.1]: codeName: 'InvalidPipelineOperator',
2020-12-09T16:22:24.955906+00:00 app[worker.1]: '$clusterTime': {
2020-12-09T16:22:24.955906+00:00 app[worker.1]: clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 4, high_: 1607530944 },
2020-12-09T16:22:24.955907+00:00 app[worker.1]: signature: {
2020-12-09T16:22:24.955907+00:00 app[worker.1]: hash: Binary {
2020-12-09T16:22:24.955908+00:00 app[worker.1]: _bsontype: 'Binary',
2020-12-09T16:22:24.955908+00:00 app[worker.1]: sub_type: 0,
2020-12-09T16:22:24.955908+00:00 app[worker.1]: position: 20,
2020-12-09T16:22:24.955908+00:00 app[worker.1]: buffer: Buffer(20) [Uint8Array] [
2020-12-09T16:22:24.955909+00:00 app[worker.1]: 183, 174, 253, 5, 233, 29,
2020-12-09T16:22:24.955909+00:00 app[worker.1]: 125, 241, 33, 191, 72, 14,
2020-12-09T16:22:24.955910+00:00 app[worker.1]: 20, 58, 186, 92, 243, 169,
2020-12-09T16:22:24.955910+00:00 app[worker.1]: 243, 203
2020-12-09T16:22:24.955910+00:00 app[worker.1]: ]
2020-12-09T16:22:24.955911+00:00 app[worker.1]: },
2020-12-09T16:22:24.955911+00:00 app[worker.1]: keyId: Long { _bsontype: 'Long', low_: 3, high_: 1599833582 }
2020-12-09T16:22:24.955911+00:00 app[worker.1]: }
2020-12-09T16:22:24.955912+00:00 app[worker.1]: }
2020-12-09T16:22:24.955912+00:00 app[worker.1]: }
注释掉管道可以消除我部署时的错误,所以至少我知道问题出在更改流上。我仍然不知道为什么它在本地工作而不是在部署中工作。我也在我的项目中使用 nodejs 事件发射器,如果这与此有关的话。我知道 changeStreams 使用来自节点的相同事件发射器库。
欢迎任何帮助;谢谢。
您在此处包含两次冒号 '$or:' :
,请尝试将其更改为 '$or' :
。
所以下面的代码在本地运行,没有出现这个错误。但是,当我使用以下代码部署到 heroku 时:
const profPipeLine = [
{
'$match': {
'$expr': {
'$or:': [
{'$eq': ['operationType', 'insert']},
{'$eq': ['operationType', 'update']},
{'$eq': ['operationType', 'delete']}
]
}
}
}
];
const options = { 'fullDocument': 'updateLookup' };
const profileStream = MatchProfile.watch(profPipeLine, options);
profileStream.on('change', next => {
....
})
我收到这个错误:
2020-12-09T16:22:24.955884+00:00 app[worker.1]: events.js:291
2020-12-09T16:22:24.955886+00:00 app[worker.1]: throw er; // Unhandled 'error' event
2020-12-09T16:22:24.955886+00:00 app[worker.1]: ^
2020-12-09T16:22:24.955887+00:00 app[worker.1]:
2020-12-09T16:22:24.955887+00:00 app[worker.1]: MongoError: Unrecognized expression '$or:'
2020-12-09T16:22:24.955888+00:00 app[worker.1]: at MessageStream.messageHandler (/app/node_modules/mongodb/lib/cmap/connection.js:268:20)
2020-12-09T16:22:24.955888+00:00 app[worker.1]: at MessageStream.emit (events.js:314:20)
2020-12-09T16:22:24.955889+00:00 app[worker.1]: at processIncomingData (/app/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
2020-12-09T16:22:24.955889+00:00 app[worker.1]: at MessageStream._write (/app/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
2020-12-09T16:22:24.955889+00:00 app[worker.1]: at doWrite (_stream_writable.js:403:12)
2020-12-09T16:22:24.955890+00:00 app[worker.1]: at writeOrBuffer (_stream_writable.js:387:5)
2020-12-09T16:22:24.955891+00:00 app[worker.1]: at MessageStream.Writable.write (_stream_writable.js:318:11)
2020-12-09T16:22:24.955891+00:00 app[worker.1]: at TLSSocket.ondata (_stream_readable.js:718:22)
2020-12-09T16:22:24.955891+00:00 app[worker.1]: at TLSSocket.emit (events.js:314:20)
2020-12-09T16:22:24.955892+00:00 app[worker.1]: at addChunk (_stream_readable.js:297:12)
2020-12-09T16:22:24.955892+00:00 app[worker.1]: at readableAddChunk (_stream_readable.js:272:9)
2020-12-09T16:22:24.955893+00:00 app[worker.1]: at TLSSocket.Readable.push (_stream_readable.js:213:10)
2020-12-09T16:22:24.955893+00:00 app[worker.1]: at TLSWrap.onStreamRead (internal/stream_base_commons.js:188:23)
2020-12-09T16:22:24.955894+00:00 app[worker.1]: Emitted 'error' event on ChangeStream instance at:
2020-12-09T16:22:24.955894+00:00 app[worker.1]: at ChangeStream.<anonymous> (/app/node_modules/mongoose/lib/cursor/ChangeStream.js:41:51)
2020-12-09T16:22:24.955898+00:00 app[worker.1]: at ChangeStream.emit (events.js:314:20)
2020-12-09T16:22:24.955899+00:00 app[worker.1]: at processError (/app/node_modules/mongodb/lib/change_stream.js:571:38)
2020-12-09T16:22:24.955899+00:00 app[worker.1]: at ChangeStreamCursor.<anonymous> (/app/node_modules/mongodb/lib/change_stream.js:435:5)
2020-12-09T16:22:24.955900+00:00 app[worker.1]: at ChangeStreamCursor.emit (events.js:314:20)
2020-12-09T16:22:24.955900+00:00 app[worker.1]: at /app/node_modules/mongodb/lib/core/cursor.js:343:16
2020-12-09T16:22:24.955900+00:00 app[worker.1]: at /app/node_modules/mongodb/lib/core/cursor.js:736:9
2020-12-09T16:22:24.955901+00:00 app[worker.1]: at /app/node_modules/mongodb/lib/change_stream.js:329:9
2020-12-09T16:22:24.955901+00:00 app[worker.1]: at done (/app/node_modules/mongodb/lib/core/cursor.js:458:7)
2020-12-09T16:22:24.955902+00:00 app[worker.1]: at /app/node_modules/mongodb/lib/core/cursor.js:533:11
2020-12-09T16:22:24.955902+00:00 app[worker.1]: at executeCallback (/app/node_modules/mongodb/lib/operations/execute_operation.js:70:5)
2020-12-09T16:22:24.955902+00:00 app[worker.1]: at callbackWithRetry (/app/node_modules/mongodb/lib/operations/execute_operation.js:122:14)
2020-12-09T16:22:24.955903+00:00 app[worker.1]: at /app/node_modules/mongodb/lib/operations/command_v2.js:86:9
2020-12-09T16:22:24.955903+00:00 app[worker.1]: at /app/node_modules/mongodb/lib/cmap/connection_pool.js:348:13
2020-12-09T16:22:24.955904+00:00 app[worker.1]: at handleOperationResult (/app/node_modules/mongodb/lib/core/sdam/server.js:558:5)
2020-12-09T16:22:24.955904+00:00 app[worker.1]: at MessageStream.messageHandler (/app/node_modules/mongodb/lib/cmap/connection.js:268:11) {
2020-12-09T16:22:24.955904+00:00 app[worker.1]: operationTime: Timestamp { _bsontype: 'Timestamp', low_: 4, high_: 1607530944 },
2020-12-09T16:22:24.955905+00:00 app[worker.1]: ok: 0,
2020-12-09T16:22:24.955905+00:00 app[worker.1]: code: 168,
2020-12-09T16:22:24.955905+00:00 app[worker.1]: codeName: 'InvalidPipelineOperator',
2020-12-09T16:22:24.955906+00:00 app[worker.1]: '$clusterTime': {
2020-12-09T16:22:24.955906+00:00 app[worker.1]: clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 4, high_: 1607530944 },
2020-12-09T16:22:24.955907+00:00 app[worker.1]: signature: {
2020-12-09T16:22:24.955907+00:00 app[worker.1]: hash: Binary {
2020-12-09T16:22:24.955908+00:00 app[worker.1]: _bsontype: 'Binary',
2020-12-09T16:22:24.955908+00:00 app[worker.1]: sub_type: 0,
2020-12-09T16:22:24.955908+00:00 app[worker.1]: position: 20,
2020-12-09T16:22:24.955908+00:00 app[worker.1]: buffer: Buffer(20) [Uint8Array] [
2020-12-09T16:22:24.955909+00:00 app[worker.1]: 183, 174, 253, 5, 233, 29,
2020-12-09T16:22:24.955909+00:00 app[worker.1]: 125, 241, 33, 191, 72, 14,
2020-12-09T16:22:24.955910+00:00 app[worker.1]: 20, 58, 186, 92, 243, 169,
2020-12-09T16:22:24.955910+00:00 app[worker.1]: 243, 203
2020-12-09T16:22:24.955910+00:00 app[worker.1]: ]
2020-12-09T16:22:24.955911+00:00 app[worker.1]: },
2020-12-09T16:22:24.955911+00:00 app[worker.1]: keyId: Long { _bsontype: 'Long', low_: 3, high_: 1599833582 }
2020-12-09T16:22:24.955911+00:00 app[worker.1]: }
2020-12-09T16:22:24.955912+00:00 app[worker.1]: }
2020-12-09T16:22:24.955912+00:00 app[worker.1]: }
注释掉管道可以消除我部署时的错误,所以至少我知道问题出在更改流上。我仍然不知道为什么它在本地工作而不是在部署中工作。我也在我的项目中使用 nodejs 事件发射器,如果这与此有关的话。我知道 changeStreams 使用来自节点的相同事件发射器库。
欢迎任何帮助;谢谢。
您在此处包含两次冒号 '$or:' :
,请尝试将其更改为 '$or' :
。