Closed lewisakura closed 2 years ago
Can confirm
yeah, that's true but this library is based on rust's MongoDB library which doesn't seem to have stringUrl connection. but still, if @manyuanrong implement this. that would be cool though.
I hope to describe the problem as a more detailed feature request. Indicate what input is received and what result is expected
Hello, I went through the same thing a few hours ago, but I discovered that there is another way to connect "connectWithOptions". I leave you an example:
import { MongoClient } from "https://deno.land/x/mongo@v0.7.0/mod.ts";
const client = new MongoClient();
const opciones = {
hosts: ['mongo1:27017','mongo2:27017','mongo3:27017','mongo4:27017' ],
replSetName:'rs0'
}
//client.connectWithOptions(opciones);
client.connectWithOptions(opciones);
console.log('CLIENTE: ', client);
const db = client.database("deno");
const users = db.collection("dispositivos");
This code works for me in W10 but it doesn't work for me in Debian 9. And I do not know why...
@manyuanrong In the Node.js driver, the connection string is used to determine what servers the driver needs to connect to. What the Rust driver (and therefore the deno_mongo driver) does is that it's using the data from the primary server in the replica. Because this data is specifically for the servers, it shouldn't be used by the drivers when connecting. Instead, the connection string (which contains the IPs to the servers) should be used.
Until this issue is fixed, use this as a temporary solution (Windows only):
C:\Windows\System32\drivers\etc\hosts
in a text editor of your choiceIP HOST
IP HOST2
IP HOST3
ipconfig /flushdns
in a terminalI have the same problem also without replica. Is it possible to set the "moongose" option { useUnifiedTopology: true } in the connection?
We have a replica set on MongoDB configured with hosts set in the /etc/hosts file which don't exist on our development machines. When using a URL with the actual domains that are public, deno_mongo uses the information from the primary server instead of the URL. This is not the behaviour we get with Node's MongoDB or with MongoDB Compass (which both use the servers in the connection URL).