question

StevenCheng71 avatar image
0 Votes"
StevenCheng71 asked NavtejSaini-MSFT commented

How to get inserted change stream data, use cosmosDB and mongo API ?

I use mongoose to watch mongodb.
And use this docs example.
https://docs.microsoft.com/en-us/azure/cosmos-db/mongodb-change-streams?tabs=javascript

Like this:


start(): void {
        let defaultSchemaChangeStream = this._alertDocumentModel.watch([
                {$match: {"operationType": {$in: ["insert"]}}},
                {$project: {"_id": 1, "fullDocument": 1, "ns": 1, "documentKey": 1}}
            ],
            {fullDocument: "updateLookup"});
        console.log(`defaultSchemaChangeStream= ${JSON.stringify(defaultSchemaChangeStream)}`

        defaultSchemaChangeStream.on('change', async (data: any) => {
            console.log(`alert collection has changed data is`, data, `data.operationType`, data.operationType)
            console.log(new Date(), `[Server]Alert have insert`, data.fullDocument)
            this._messageSender.sendMessages([
                {body: data.fullDocument}
            ]).then(r => console.log(`[Server]server send service bus`, r))
        })
    }


And run nodejs , get error message:
MongoError: Match stage must include constraints on "operationType" to include "insert", "update", and "replace".
But I just want "insert" change streams , how to do that??


azure-cosmos-db
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@47173299 We are checking this and will get back to you.

1 Vote 1 ·

Thanks for your help!

0 Votes 0 ·

1 Answer

NavtejSaini-MSFT avatar image
0 Votes"
NavtejSaini-MSFT answered NavtejSaini-MSFT commented

@StevenCheng71

We checked this our team and they have conveyed that the code won't work without putting all three: insert, update, replace - like the example in the docs linked. This was a UX decision to make what is being returned explicit to the user.

They will be making the change to the document as well. They do have plans to add the filter in future but with no ETA.

Please do add your feedback about the product here and let us know if you need any further info.

Regards
Navtej S


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@StevenCheng71 Please let us know if you have any further questions.

0 Votes 0 ·