I am using the watch method to listen to the change-steam events in the MongoDB database. The "fullDocument" that I'm getting after the change event at the database is quite heavy, so I'm trying to filter out the unnecessary field. Below is the syntax:
const pipelines = [
{
$match: {
operationType: { $in: ["insert", "update", "replace"] },
},
},
{
$project: {
fullDocument: {
form: 0,
},
},
},
];
const options = { fullDocument: "updateLookup" };
const changeStream = collection.watch(pipelines, options);
This code is not working and throwing the below error:
MongoError: Change stream must be followed by a match and then a project stage
at MessageStream.messageHandler (node_modules/mongodb/lib/cmap/connection.js:268:20)
at MessageStream.emit (events.js:198:13)
at processIncomingData (node_modules/mongodb/lib/cmap/message_stream.js:144:12)
at MessageStream._write (node_modules/mongodb/lib/cmap/message_stream.js:42:5)
at doWrite (_stream_writable.js:415:12)
at writeOrBuffer (_stream_writable.js:399:5)
at MessageStream.Writable.write (_stream_writable.js:299:11)
at TLSSocket.ondata (_stream_readable.js:710:20)
at TLSSocket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
Additional details:
MongoDB version: 3.2.0
Mongo client version: 3.6.3
Is there anything missing from my side? If I try {fullDocument: 1}
then it works fine.
question from:
https://stackoverflow.com/questions/66066945/mongodb-change-stream-processor-unable-to-use-project 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…