question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Current db does not support change stream (not a replica set)

See original GitHub issue

I updated to the latest release and I am getting these errors regularly. I am on my local dev machine with MongoDB 4.2.8.

09:27:12.895|Error|22||Current db does not support change stream (not a replica set), consider using 'CheckQueuedJobsStrategy.TailNotificationsCollection' instead MongoDB.Driver.MongoCommandException: Command aggregate failed: The $changeStream stage is only supported on replica sets. at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol1.ProcessResponse(ConnectionId connectionId, CommandMessage responseMessage) at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol1.Execute(IConnection connection, CancellationToken cancellationToken) at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol1.Execute(IConnection connection, CancellationToken cancellationToken) at MongoDB.Driver.Core.Servers.Server.ServerChannel.ExecuteProtocol[TResult](IWireProtocol1 protocol, ICoreSession session, CancellationToken cancellationToken) at MongoDB.Driver.Core.Servers.Server.ServerChannel.Command[TResult](ICoreSession session, ReadPreference readPreference, DatabaseNamespace databaseNamespace, BsonDocument command, IEnumerable1 commandPayloads, IElementNameValidator commandValidator, BsonDocument additionalOptions, Action1 postWriteAction, CommandResponseHandling responseHandling, IBsonSerializer1 resultSerializer, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken) at MongoDB.Driver.Core.Operations.CommandOperationBase1.ExecuteProtocol(IChannelHandle channel, ICoreSessionHandle session, ReadPreference readPreference, CancellationToken cancellationToken) at MongoDB.Driver.Core.Operations.ReadCommandOperation1.ExecuteAttempt(RetryableReadContext context, Int32 attempt, Nullable1 transactionNumber, CancellationToken cancellationToken) at MongoDB.Driver.Core.Operations.RetryableReadOperationExecutor.Execute[TResult](IRetryableReadOperation1 operation, RetryableReadContext context, CancellationToken cancellationToken) at MongoDB.Driver.Core.Operations.ReadCommandOperation1.Execute(RetryableReadContext context, CancellationToken cancellationToken) at MongoDB.Driver.Core.Operations.AggregateOperation1.Execute(RetryableReadContext context, CancellationToken cancellationToken) at MongoDB.Driver.Core.Operations.ChangeStreamOperation1.ExecuteAggregateOperation(RetryableReadContext context, CancellationToken cancellationToken) at MongoDB.Driver.Core.Operations.ChangeStreamOperation1.Execute(IReadBinding binding, CancellationToken cancellationToken) at MongoDB.Driver.OperationExecutor.ExecuteReadOperation[TResult](IReadBinding binding, IReadOperation1 operation, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl1.ExecuteReadOperation[TResult](IClientSessionHandle session, IReadOperation1 operation, ReadPreference readPreference, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl1.ExecuteReadOperation[TResult](IClientSessionHandle session, IReadOperation1 operation, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl1.Watch[TResult](IClientSessionHandle session, PipelineDefinition2 pipeline, ChangeStreamOptions options, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl1.<>c__DisplayClass66_01.<Watch>b__0(IClientSessionHandle session) at MongoDB.Driver.MongoCollectionImpl1.UsingImplicitSession[TResult](Func2 func, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl1.Watch[TResult](PipelineDefinition2 pipeline, ChangeStreamOptions options, CancellationToken cancellationToken) at Hangfire.Mongo.MongoJobQueueWatcher.Execute(CancellationToken cancellationToken) at Hangfire.Server.ServerProcessDispatcherBuilder.ExecuteComponent(Guid executionId, Object state) at Hangfire.Processing.BackgroundExecution.Run(Action2 callback, Object state)`

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
gottscjcommented, Jan 4, 2022

@provanguard,

you have a couple of options.

  1. use ‘TailNotificationsCollection’ which tails a capped collection, which is used to notify all Hangfire.Mongo instances of enqueued jobs. This is basically the default behavior before using the “watch” feature and it works on all mongod configurations. In hindsight, I should described this better in the release notes.

  2. Use a “replica set” or “single node replica” in your local setup which supports the same features as your production environment. I have created a dotnet tool for this which I use when in development.

  3. use different strategy based on configuration.

Thanks Jonas

1reaction
gottscjcommented, Nov 22, 2021

@provanguard, sorry for the late reply, I have been on vacation.

It seems my error description is not descriptive enough. I will make sure to update it for next release.

there are certain features mongodb doesnt support if running as a single node. normally mongodb runs with replica sets. eg. multiple instances/processes of mongod. these features include the “watch” feature. https://docs.mongodb.com/manual/reference/method/db.collection.watch/

the watch feature is now the default behavior for observing enqueued jobs. If you are using a single mongod node, you need to change the “CheckQueuedJobsStrategy” in MongoStorageOptions to “TailNotificationsCollection” or “Poll” depending on your needs. You can configure mongo to run as a “single node replica set”. I have created a dotnet tool enabling this: https://github.com/gottscj/MongoRunner

please also see #299.

hope this helps! Br

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Change Streams in a standalone database
It looks like Change Streams only work if the database is initialized as a replica set. I was able to shutdown the database...
Read more >
"The $changeStream stage is only supported on replica ...
MongoDB change streams option is available only in replica sets setup. However, you can update your standalone installation to a single node ...
Read more >
Using Change Streams with Amazon DocumentDB
Reading from change streams on a replica instance is not currently supported. When invoking the watch() API operation, you must specify a primary...
Read more >
Change Streams — MongoDB Manual
Change streams only notify on data changes that have persisted to a majority of data-bearing members in the replica set. This ensures that...
Read more >
Create a single-server replica set only for watching on ...
I want to subscribe to change streams on that DB, and for that they must be members of a replica set. Is it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found