Edits history of script submission #33 for ' Search Documents (mongodb)'

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    import { Bson, MongoClient } from "https://deno.land/x/[email protected]/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",
      },
    });
    
    @param: {object} filter - Object to filter mongodb documents
    example:
    { username: { $ne: null } }
    
    */
    
    export async function main(
        mongodb_con: wmill.Resource<"mongodb">,
        db_name: string,
        collection_name: string,
        filter: object
    ) {
        const client = new MongoClient();
    
        // Connecting to a Mongo Atlas Database
        const resp = await client.connect(mongodb_con);
    
        const db = client.database(db_name);
        const collection = db.collection(collection_name);
    
        const all_collection = await collection.find(filter).toArray();
    
        return (all_collection ? 'Documents Found in MongoDB' : 'Documents Not Found');
    }

    Submitted by rossmccrann 1393 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    import { Bson, MongoClient } from "https://deno.land/x/[email protected]/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",
      },
    });
    
    @param: {object} filter - Object to filter mongodb documents
    example:
    { username: { $ne: null } }
    
    */
    
    export async function main(
        mongodb_con: wmill.Resource<"mongodb">,
        db_name: string,
        collection_name: string,
        objectId: string,
        filter: object
    ) {
        const client = new MongoClient();
    
        // Connecting to a Mongo Atlas Database
        const resp = await client.connect(mongodb_con);
    
        const db = client.database(db_name);
        const collection = db.collection(collection_name);
    
        const all_collection = await collection.find(filter).toArray();
    
        return (all_collection ? 'Documents Found in MongoDB' : 'Documents Not Found');
    }
    

    Submitted by rossmccrann 1393 days ago