thekid / dialog

Dialog photoblog
2 stars 1 forks source link

MongoDB error "not primary and secondaryOk=false" #13

Closed thekid closed 1 year ago

thekid commented 1 year ago
Caused by Exception com.mongodb.Error (#13435:NotPrimaryNoSecondaryOk "not primary and secondaryOk=false")
  at com.mongodb.Error::newInstance(array[7]) [line 201 of Connection.class.php] 
  at com.mongodb.io.Connection::message(array[5], array[1]) [line 163 of Protocol.class.php] 
  at com.mongodb.io.Protocol::send(array[1], array[4], (0x14)'reading with primary') [line 205 of Protocol.class.php] 
  at com.mongodb.io.Protocol::read(NULL, array[4]) [line 235 of Collection.class.php] 
  at com.mongodb.Collection::aggregate(array[4]) [line 38 of Repository.php] 
  at de.thekid.dialog.Repository::entries(de.thekid.dialog.Pagination{}, 3) [line 14 of Feed.php] 
  at de.thekid.dialog.web.Feed::listing((0x1)'3') [line 0 of StackTraceElement.class.php] 
  at ReflectionMethod::invokeArgs(de.thekid.dialog.web.Feed{}, array[1]) [line 88 of Method.class.php] 
  at lang.reflect.Method::invoke(de.thekid.dialog.web.Feed{}, array[1]) [line 85 of Delegate.class.php] 
  ... 16 more
thekid commented 1 year ago

This happens when not setting a readPreference, which then defaults to primary, and only reads from the primary.

thekid commented 1 year ago

Can be fixed by appending e.g. ?readPreference=primaryPreferred or ?readPreference=secondaryPreferred to the MONGO_URI environment variable; which would then prefer reading from the primary (or secondary) but would also be OK reading from the respective others; see https://docs.mongodb.com/manual/core/read-preference-mechanics/

Question is if we should supply this as a default value.