Vishal Patel
Vishal Patel

Reputation: 97

Get document whenever there is a new document inserted in collection

I developing application using mongodb and node js. I want to get document from collection using node js mongoose whenever a new document inserted in the collection(document inserted from python side).Currently, I have query which i run in time interval of 1 seconds using setInterval.

So, Is there any another efficient way without setinterval.

Upvotes: 0

Views: 58

Answers (2)

Ashish Modi
Ashish Modi

Reputation: 7770

I guess this can be easily achieved by using mongodb change streams.

You can see more about here with code examples.

power of mongodb change streams

Basically listen for insert operation type and react accordingly. This is much efficient then tailing oplog.

Upvotes: 1

husanu
husanu

Reputation: 304

You can use tailable cursors on mongodb's oplog

Upvotes: 1

Related Questions