You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Brand new install of mongoDB on a windows machine (A) with a db and collections.
It works fine...and a webapp (not mine) that displays data from the db , on this same machine (A) also works well...and proves that all is well on the mongoDB end.
But, I have a development machine (B) where I am writing a node app to access the data on Machine A (it is on the same segment). I am running into a strange problem.
Up until yesterday, it was working fine. I could happily access mongo on Machine A from node on Machine B (with useUnifiedTopology=true
But then, I decided to migrate my mongoDB to a one-node replicaSet to take advantage of the "watch" function. The process seems to have worked on the mongodb side. That webapp I referenced above is happily working, as is Compass. I see the oplog.rs and replset.* entries on the mongoDB instance.
But on my remote development machine (B), I can no longer connect to mongoDB on machine A, UNLESS I set useUnifiedTopology to false. When set to false, everything works (with the deprecation warning). That includes the collection.watch().on functionality. So the replication set seems to be working.
But when useUnifiedTopology=true, I get a DB connection error: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017.
BTW Compass works fine on the development machine.
My barebones code is below. I have tried a million variants, like wrapping the connection in an await - but all to no avail. What am I missing? Or is it a bug?
import mongoose from "mongoose";
const url = "mongodb://192.168.1.xxx:27017/MyDbName";
var options = {
keepAlive: true,
useNewUrlParser: true,
useUnifiedTopology: false,
connectWithNoPrimary: true
}
mongoose.connect(url, options);
var db = mongoose.connection;
db.on("error", console.error.bind(console, "DB connection error:"));
db.once("open", function () {
console.log("DB connection successful");
});
The text was updated successfully, but these errors were encountered:
Of course, after hours and hours of searching, I just found the solution in another issue.
Hopefully it will help others: #9836 (comment)
append ?directConnection=true to the url.
Still feels like a bug or at least a doc change to me -- but what do I know.
directConnection=true means you aren't connecting to a replica set, you're connecting directly to one mongod server. Which may be fine for your use case, but defeats the point of having a replica set.
Hi,
Bit of a mongo newbie, so forgive me if I use the wrong descriptive language.
Brand new install of mongoDB on a windows machine (A) with a db and collections.
It works fine...and a webapp (not mine) that displays data from the db , on this same machine (A) also works well...and proves that all is well on the mongoDB end.
But, I have a development machine (B) where I am writing a node app to access the data on Machine A (it is on the same segment). I am running into a strange problem.
Up until yesterday, it was working fine. I could happily access mongo on Machine A from node on Machine B (with
useUnifiedTopology=true
But then, I decided to migrate my mongoDB to a one-node replicaSet to take advantage of the "watch" function. The process seems to have worked on the mongodb side. That webapp I referenced above is happily working, as is Compass. I see the oplog.rs and replset.* entries on the mongoDB instance.
But on my remote development machine (B), I can no longer connect to mongoDB on machine A, UNLESS I set useUnifiedTopology to false. When set to false, everything works (with the deprecation warning). That includes the
collection.watch().on
functionality. So the replication set seems to be working.But when
useUnifiedTopology=true
, I get aDB connection error: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
.BTW Compass works fine on the development machine.
My barebones code is below. I have tried a million variants, like wrapping the connection in an await - but all to no avail. What am I missing? Or is it a bug?
The text was updated successfully, but these errors were encountered: