将“stream”更改功能在MongoDB中用于时间序列数据集是否有效?

huangapple go评论62阅读模式
英文:

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。
将“stream”更改功能在MongoDB中用于时间序列数据集是否有效?

以下是我的参考资料:
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.
将“stream”更改功能在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

huangapple
  • 本文由 发表于 2023年3月4日 01:14:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75630051.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定