import * as wmill from "https://deno.land/x/windmill@v1.19.2/mod.ts";
import { Bson, MongoClient } from "https://deno.land/x/mongo@v0.30.1/mod.ts";
/*
@param: {wmill.Resource} mongodb - Resource containing mongodb connection object
example:
await client.connect({
db: "<db_name>",
tls: true,
servers: [
{
host: "<db_cluster_url>",
port: 27017,
},
],
credential: {
username: "<username>",
password: "<password>",
db: "<db_name>",
mechanism: "SCRAM-SHA-1",
},
});
*/
export async function main(
mongodb_con: wmill.Resource<"mongodb">,
db_name: string,
collection_name: string,
objectId: string
) {
const client = new MongoClient();
// Connecting to a Mongo Atlas Database
const resp = await client.connect(mongodb_con);
const db = client.database(db_name);
const collect = db.collection(collection_name);
const collect_single = await collect.findOne({ _id: objectId });
return (collect_single ? 'Document Found in MongoDB' : 'Document Not Found');
}
Submitted by rossmccrann 857 days ago
import * as wmill from "https://deno.land/x/windmill@v1.19.2/mod.ts";
import { Bson, MongoClient } from "https://deno.land/x/mongo@v0.30.1/mod.ts";
/*
@param: {wmill.Resource} mongodb - Resource containing mongodb connection object
example:
{
db: "<db_name>",
tls: true,
servers: [
{
host: "<db_cluster_url>",
port: 27017,
},
],
credential: {
username: "<username>",
password: "<password>",
db: "<db_name>",
mechanism: "SCRAM-SHA-1",
},
}
*/
export async function main(
mongodb_con: wmill.Resource<"mongodb">,
deleteId: number,
database: string,
collection: string
) {
const client = new MongoClient();
// Connecting to a Mongo Atlas Database
const resp = await client.connect(mongodb_con);
const db = client.database(database);
const users = db.collection<Schema>(collection);
const deleteCount = await users.deleteOne({ _id: deleteId });
return 'Document deleted in MongoDB';
}
Submitted by rossmccrann 857 days ago