Open playerx opened 2 years ago
https://github.com/erfanium/deno-deploy-mongo this demo uses MongoDB Atlas for its database with no problem. do you use any non-default options when you creating a database?
This issue needs a reproduction steps for me
I've a simple script like this:
import { MongoClient } from "https://deno.land/x/mongo@v0.29.0/mod.ts";
const client = new MongoClient();
const db = await client.connect(
"mongodb+srv://USER:PASSWORD@jok-prod.RANDOM.mongodb.net/jok?authMechanism=SCRAM-SHA-1"
);
const names = await db.listCollectionNames();
console.log(names);
and it fails, I've tried the same script on different mongo atlas clusters and had the same error.
Can you share the structure of the connection string you are using? Maybe I miss something there
Ah it seems the database name in the connection string isn't supported for now. It started working once I've updated connection string like this:
"mongodb+srv://USER:PASSWORD@jok-prod.RANDOM.mongodb.net/?authMechanism=SCRAM-SHA-1"
are you sure? maybe you should use authSource
property
I've tried calling parse
function for the connectionString I was using and here is the result:
Input:
"mongodb+srv://USER:PASSWORD@jok-prod.RANDOM.mongodb.net/jok?authMechanism=SCRAM-SHA-1"
Output:
{
servers: [
{ host: "jok-prod-shard-00-01.RAND.mongodb.net.", port: 27017 },
{ host: "jok-prod-shard-00-02.RAND.mongodb.net.", port: 27017 },
{ host: "jok-prod-shard-00-00.RAND.mongodb.net.", port: 27017 }
],
authSource: "admin",
replicaSet: "atlas-132kf5-shard-0",
db: "jok",
credential: {
username: "USER",
password: "PASSWORD",
db: "jok",
mechanism: "SCRAM-SHA-1"
},
compression: [],
tls: true,
retryWrites: true
}
As you can see it changed credentials database as well and that's the issue here I think
i think that's an expected behavior, just use something like:
mongodb+srv://USER:PASSWORD@jok-prod.RANDOM.mongodb.net/jok?authMechanism=SCRAM-SHA-1&authSource=admin
The reason why I think it's an issue is that the connection string I used works properly with nodejs mongo (official) driver and many users will use the same connections string and had the same issue.
I think credential.db
should not be changed unless there will be provided authSource explicitly.
Hey, it works with local db but fails with mongodb atlas connection string, I'm using the syntax like this:
It always fails here: https://deno.land/x/mongo@v0.29.0/src/client.ts#L41 with error:
Can you share if it's a known issue or do I need to provide some additional params?