GoodDB
    Preparing search index...

    Function findAndUpdateMany

    • Find multiple values in an array and update them

      Parameters

      • this: GoodDB
      • key: string

        The key of the array to search

      • findCallback: (value: any, index: number, obj: any[]) => unknown

        The callback function to find the elements

      • updateCallback: (value: any, index: number, obj: any[]) => any

        The callback function to update the found elements

      • Optionaloptions: methodOptions

        The options to use

      Returns any[] | Promise<any[]>

      A promise if the driver is async, otherwise an array of updated elements

      const db = new GoodDB(new JSONDriver({
      path: './database.json'
      }));

      db.findAndUpdateMany('users',
      (user) => user.active === true,
      (user) => { user.status = 'verified'; return user; }
      );
      const db = new GoodDB(new MongoDBDriver({
      uri: "..."
      }));

      await db.connect();

      await db.findAndUpdateMany('users',
      (user) => user.active === true,
      (user) => { user.status = 'verified'; return user; }
      );