Edits history of script submission #261 for ' Update a Document (mongodb)'

  • deno
    One script reply has been approved by the moderators
    Ap­pro­ved
    import { MongoClient } from "https://deno.land/x/[email protected]/mod.ts";
    
    /**
     * @param data_source For example: `Cluster0`
     *
     * @param filter For example: `{ "_id": "01234" }`
     *
     * @param upsert If `true` and no documents match the `filter`,
     * then a new document will be created with the values of `document`.
     * Default is `false`.
     */
    type MongodbRest = {
      endpoint: string;
      api_key: string;
    };
    export async function main(
      auth: MongodbRest,
      data_source: string,
      database: string,
      collection: string,
      filter: Record<string, any>,
      document: Record<string, any>,
      upsert?: boolean,
    ) {
      const client = new MongoClient({
        endpoint: auth.endpoint,
        dataSource: data_source,
        auth: { apiKey: auth.api_key },
      });
      const docs = client.database(database).collection(collection);
      upsert = typeof upsert === "boolean" ? upsert : undefined;
      return await docs.updateOne(filter, document, { upsert });
    }
    

    Submitted by hugo697 370 days ago

  • deno
    import { MongoClient } from "https://deno.land/x/[email protected]/mod.ts";
    
    /**
     * @param data_source For example: `Cluster0`
     *
     * @param filter For example: `{ "_id": "01234" }`
     *
     * @param upsert If `true` and no documents match the `filter`,
     * then a new document will be created with the values of `document`.
     * Default is `false`.
     */
    type MongodbRest = {
      endpoint: string;
      api_key: string;
    };
    export async function main(
      auth: MongodbRest,
      data_source: string,
      database: string,
      collection: string,
      filter: Record<string, any>,
      document: Record<string, any>,
      upsert?: boolean,
    ) {
      const client = new MongoClient({
        endpoint: auth.endpoint,
        dataSource: data_source,
        auth: { apiKey: auth.api_key },
      });
      const docs = client.database(database).collection(collection);
      upsert = typeof upsert === "boolean" ? upsert : undefined;
      return await docs.updateOne(filter, document, { upsert });
    }
    

    Submitted by admin 1002 days ago

  • deno
    import { MongoClient } from "https://deno.land/x/[email protected]/mod.ts";
    
    /**
     * @param data_source For example: `Cluster0`
     * 
     * @param filter For example: `{ "_id": "01234" }`
     * 
     * @param upsert If `true` and no documents match the `filter`, 
     * then a new document will be created with the values of `document`.
     * Default is `false`.
     */
    type MongodbRest = {
      endpoint: string;
      api_key: string;
    };
    export async function main(
      auth: MongodbRest,
      data_source: string,
      database: string,
      collection: string,
      filter: Record<string, any>,
      document: Record<string, any>,
      upsert?: boolean
    ) {
      const client = new MongoClient({
        endpoint: auth.endpoint,
        dataSource: data_source,
        auth: { apiKey: auth.api_key },
      });
      const docs = client.database(database).collection(collection)
      upsert = typeof upsert === 'boolean' ? upsert : undefined
      return await docs.updateOne(filter, document, { upsert })
    }
    

    Submitted by admin 1005 days ago

  • deno
    import { Resource } from "https://deno.land/x/[email protected]/mod.ts";
    import { MongoClient } from "https://deno.land/x/[email protected]/mod.ts";
    
    /**
     * @param data_source For example: `Cluster0`
     * 
     * @param filter For example: `{ "_id": "01234" }`
     * 
     * @param upsert If `true` and no documents match the `filter`, 
     * then a new document will be created with the values of `document`.
     * Default is `false`.
     */
    export async function main(
      auth: Resource<"mongodb_rest">,
      data_source: string,
      database: string,
      collection: string,
      filter: Record<string, any>,
      document: Record<string, any>,
      upsert?: boolean
    ) {
      const client = new MongoClient({
        endpoint: auth.endpoint,
        dataSource: data_source,
        auth: { apiKey: auth.api_key },
      });
      const docs = client.database(database).collection(collection)
      upsert = typeof upsert === 'boolean' ? upsert : undefined
      return await docs.updateOne(filter, document, { upsert })
    }
    

    Submitted by adam186 1134 days ago

  • deno
    import { Resource } from "https://deno.land/x/[email protected]/mod.ts";
    import { MongoClient } from "https://deno.land/x/[email protected]/mod.ts";
    
    /**
     * @param data_source For example: `Cluster0`
     * 
     * @param filter For example: `{ "_id": "01234" }`
     * 
     * @param upsert If `true` and no documents match the `filter`, 
     * then a new document will be created with the values of `document`.
     * Default is `false`.
     */
    export async function main(
      auth: Resource<"mongodb_rest">,
      data_source: string,
      database: string,
      collection: string,
      filter: Record<string, any>,
      document: Record<string, any>,
      upsert?: boolean
    ) {
      const client = new MongoClient({
        endpoint: auth.endpoint,
        dataSource: data_source,
        auth: { apiKey: auth.api_key },
      });
      const docs = client.database(database).collection(collection)
      upsert = typeof upsert === 'boolean' ? upsert : undefined
      return await docs.updateOne(filter, document, { upsert })
    }
    

    Submitted by adam186 1169 days ago

  • deno
    import { Resource } from "https://deno.land/x/[email protected]/mod.ts";
    import { MongoClient } from "https://deno.land/x/[email protected]/mod.ts";
    
    /**
     * @param data_source For example: `Cluster0`
     * 
     * @param filter For example: `{ "_id": "01234" }`
     * 
     * @param upsert If `true` and no documents match the `filter`, 
     * then a new document will be created with the values of `document`.
     * Default is `false`.
     */
    export async function main(
      auth: Resource<"mongodb_rest">,
      data_source: string,
      database: string,
      collection: string,
      filter: Record<string, any>,
      document: Record<string, any>,
      upsert?: boolean
    ) {
      const client = new MongoClient({
        endpoint: auth.endpoint,
        dataSource: data_source,
        auth: { apiKey: auth.api_key },
      });
      const docs = client.database(database).collection(collection)
      upsert = typeof upsert === 'boolean' ? upsert : undefined
      return await docs.updateOne(filter, document, { upsert })
    }
    

    Submitted by adam186 1238 days ago