Closed 61soldiers closed 1 year ago
It is really difficoult to say. The mesasge normally means that in the list of the servers provided there is not the primary (for a replica set). The fact that it doesn't work only when compiled is really strange. I'm sorry, but I do not really know how to help you. Maybe you can do some more test .... Sometimes the primary changes between the servers and mongo_dart, at present, is not able to detect this.
Found an old issue (duplicate?) in which you have commented #269
I called findOne
in a loop (with a try catch in relation to what you commented in #269) before my app started and it now seems to work
I specified in the loop that if the findOne
call failed, close db and retry again.
Don't know if this really is a temporary or a permanent fix but for now it seems good.
Seemed to work the first time i tried it, but the method above doesn't work. This is really frustrating, i'm kinda out of options now.
Which is the error? Where and when it happens? I'd need more info ...
It only happens when running the app AOT compiled and calling findOne
. My app is a discord bot btw.
Heres how i create the DB instance
final db = await Db.create(confidential.dbUri);
await db.open();
Theres really nothing much for context, just that this error comes up when doing any call (i assume) to DB.
Future<PointsDoc?> getPoints(String guildId, String discordId) async {
return PointsDoc.fromJson(await Globals.pointsCol
.findOne(where.eq('guildId', guildId).eq('discordId', discordId)));
}
Try to put a db.isConnected
before returning to see which is the value.
Will try that, but in the meantime here's an update
I can confirm that this error comes even in JIT compiled
Update again: you are not going to believe this, but i just created a new db user in mongodb cloud and copied the db URI from the connect
button on the homepage just to be sure, and its working.
Though its very unpredictable, because it worked randomly before.
After a few hours of running the bot, it just stopped working again. Gives the same master connection error.
Sometimes the primary changes between the servers and mongo_dart, at present, is not able to detect this.
Is this planned or on your roadmap by any chance ?, because, as it is, I don't think mongo_dart is really usable like that
As I wrote in the issue you mentioned what you can do is to create a wapper. In case the db is not connected you have to close and open again.
You can do it in two ways, checking if the method throws that error, or verifying the db.isConnected
flag before calling the method and, in case it is not, reconnecting to the database.
This problem is something that I have in my long term plans. Unfortunately I have not so much time to do new developments, so I cannot really tell you when a solution will be available.
I guess I'll close this now, since its been in a way resolved Still though it feels like its something that should be handled on the package's side ?, comparing to other packages in other langs.
Stack trace
This error comes when running with a compiled (AOT) dart app. Works fine on JIT. UPDATE: I can confirm that this error comes up on both AOT and JIT
Here's the the initialization