denodrivers / denodrivers/mongo

Unable to list collections in playground

Open
#415 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
511
Forks
89
PR merge metrics
No merged PRs in 30d

Description

I'm trying to list collections using the below code in playground. I see only the message `Connected!!!` in output.

```ts
import { createServer } from "node:http";
import process from "node:process";
import { MongoClient, Bson } from "https://deno.land/x/mongo@v0.33.0/mod.ts";
const url =
"mongodb+srv://userName:password@book-an-appointment-clu.rajwa.mongodb.net/?authMechanism=SCRAM-SHA-1";
const client = new MongoClient();
const dbName = "appointments-db";
let x=[];
const server = createServer(async (req, res) => {
try {
const db = await client.connect(url);

const names = await db.listCollections().toArray();
names.forEach((collection) =>
x.push(collection.name)
);
res.end("Connected!!!"+ await x+" ");
} catch (error) {
res.end("An error occurred:", error);
throw error;
} finally {
await client.close();
console.log("Connection closed.");
}
});

server.listen(8080);
```

also when I add `const database=await client.db("dbName")`, I get an error as `TypeError [ERR_UNKNOWN_ENCODING]: Unknown encoding: TypeError: client.db is not a function`
Its the same when I use `url` as `const uri =
"mongodb+srv://userName:password@book-an-appointment-clu.rajwa.mongodb.net/?retryWrites=true&w=majority&appName=book-an-appointment-cluster";`
Please lemme know where I'm going wrong.

Thanks,
Sunny

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the v0.33.0 entry point mod.ts and the MongoClient API used by client.connect, listCollections, and client.db. Reproduce the playground example, then compare the returned values and error handling; done means collection names can be listed and database selection no longer produces the reported TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
deno, mongodb, typescript
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.