英文:
Will change stream work for time series collection in MongoDB
问题
我有一个需求,需要使用更改流来跟踪插入到时间序列集合中的数据。
我尝试创建一个更改流监听器来监听该集合,但它不起作用。
我尝试了这个。这是一个示例代码,可以监听数据库集合中的所有更改,我只是将它们记录在Audit Collection中。
const dbWatch = db.watch();
await dbWatch.on('change', async (next) => {
console.log('Received change event:', next);
resumeToken = next._id;
let insertDocument = getInsertDocument(next);
switch(next.operationType){
case "insert":
insertDocument.Operation = next.operationType;
insertDocument.Description = next.fullDocument;
break;
case "update":
insertDocument.Operation = next.operationType;
insertDocument.Description = next.updateDescription;
break;
}
await AuditColl.insertOne(insertDocument);
});
但这对于时间序列集合不起作用,尽管它们已被插入,我无法接收它们。
我不确定,但我甚至读到它在MongoDB中不受支持。
https://www.mongodb.com/community/forums/t/collection-watch-for-time-series/127656
请确认。
英文:
I have a requirement where we need to use change stream to track the data insertions to Time Series collection.
I tried to create a change stream listener to that collection. But it is not working.
I tried this. This is a sample code that can listen to all changes in the database collections, I am just logging them in Audit Collection.
const dbWatch = db.watch();
await dbWatch.on('change', async (next) => {
console.log('Received change event:', next);
resumeToken = next._id;
let insertDocument = getInsertDocument(next);
switch(next.operationType){
case "insert":
insertDocument.Operation = next.operationType;
insertDocument.Description = next.fullDocument;
break;
case "update":
insertDocument.Operation = next.operationType;
insertDocument.Description = next.updateDescription;
break;
}
await AuditColl.insertOne(insertDocument);
});
But this is not working for Time Series Collections, I am unable to receive them even though they are being inserted.
I am not sure but I even read that it is not supported in MongoDB.
https://www.mongodb.com/community/forums/t/collection-watch-for-time-series/127656
Please confirm
答案1
得分: 1
看起来我在彻底研究并与相关人员讨论后找到了答案。
截至2023年3月,MongoDB不支持在时间序列集合中使用Change Streams。
以下是我的参考资料:
https://www.mongodb.com/docs/manual/core/timeseries/timeseries-limitations/
https://www.mongodb.com/community/forums/t/collection-watch-for-time-series/127656
https://www.mongodb.com/community/forums/t/mongodb-timeseries-change-stream-support-or-any-alternative/192106
英文:
Seems like I found the answer after thorough research and discussions with resource persons.
As on March 2023 MongoDB, Change Streams is Not Supported for Time Series Collections in MongoDB.
Here are my References:
https://www.mongodb.com/docs/manual/core/timeseries/timeseries-limitations/
https://www.mongodb.com/community/forums/t/collection-watch-for-time-series/127656
https://www.mongodb.com/community/forums/t/mongodb-timeseries-change-stream-support-or-any-alternative/192106
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论