Skip to content

Instantly share code, notes, and snippets.

@infysumanta
Created September 1, 2023 18:13
Show Gist options
  • Save infysumanta/bb208684dd944fd6f512e966cab5b222 to your computer and use it in GitHub Desktop.
Save infysumanta/bb208684dd944fd6f512e966cab5b222 to your computer and use it in GitHub Desktop.
This code snippet defines a route handler for the root URL ("/") of an app. It retrieves a list of users who do not have a certain field, performs some operations on each user, and then sends a JSON response with a message. This code retrieves a list of users by their ID and updates it with the user's attributes. It then sends an error message t…

Encryption Migration

Preview:
app.get<{}, MessageResponse>('/', async (req, res) => {
  const user = await User.find({ __enc_firstName: { $exists: false } }).select(
    '_id',
  );

  Promise.all(
    user.map(async (u) => {
      console.log(u._id);
      const sUser = await User.findById(u._id);
      const updateUser = await User?.updateOne(
        { _id: u._id },
        { $set: { ...sUser } },
      );
      return updateUser;
    }),
  );

  res.json({
    message: '🦄:rainbow::sparkles:👋🌎🌍:earth_asia:✨:rainbow::unicorn_face:',
  });
});

  // Old
  // UTC(-04:00) America/Detroit
  // UTC(-04:00) America/Indiana/Indianapolis
  // UTC(-04:00) America/Indiana/Marengo
  // UTC(-04:00) America/Kentucky/Monticello
  // UTC(-04:00) America/New_York
  // UTC(-04:00) America/Puerto_Rico
  // UTC(-04:00) America/Toronto
  // New
  // UTC(-04:00) America/New_York
  
await User.updateMany(
  { 
    timezone: {
      $in: [
        "UTC(-04:00) America/Detroit",
        "UTC(-04:00) America/Indiana/Indianapolis",
        "UTC(-04:00) America/Indiana/Marengo",
        "UTC(-04:00) America/Kentucky/Monticello",
        "UTC(-04:00) America/New_York",
        "UTC(-04:00) America/Puerto_Rico",
        "UTC(-04:00) America/Toronto"
      ]
    }
  },
  { $set: { timezone: "UTC(-04:00) America/New_York" } }
);


   // Old
  // UTC(-05:00) America/Chicago
  // UTC(-05:00) America/Indiana/Knox
  // UTC(-05:00) America/Indiana/Knox
  // UTC(-05:00) America/Indiana/Tell_City
  // UTC(-05:00) America/Indiana/Vevay
  // UTC(-05:00) America/Menominee
  // UTC(-05:00) America/New_York
  // UTC(-05:00) America/North_Dakota/Center
  // UTC(-05:00) America/North_Dakota/New_Salem

  // New
  // UTC(-05:00) America/Chicago

  await User.updateMany(
    { 
      timezone: {
        $in: [
          "UTC(-05:00) America/Chicago",
          "UTC(-05:00) America/Indiana/Knox",
          "UTC(-05:00) America/Indiana/Knox",
          "UTC(-05:00) America/Indiana/Tell_City",
          "UTC(-05:00) America/Indiana/Vevay",
          "UTC(-05:00) America/Menominee",
          "UTC(-05:00) America/New_York",
          "UTC(-05:00) America/North_Dakota/Center",
          "UTC(-05:00) America/North_Dakota/New_Salem"
        ]
      }
    },
    { $set: { timezone: "UTC(-05:00) America/Chicago" } }
  );




   // Old
  // UTC(-06:00) America/Denver
  // UTC(-06:00) America/Indiana/Tell_City
  // UTC(-06:00) America/North_Dakota/Center
  // UTC(-06:00) America/North_Dakota/New_Salem
  // new
  // UTC(-06:00) America/Denver
  

  await User.updateMany(
    { 
      timezone: {
        $in: [
          "UTC(-06:00) America/Denver",
          "UTC(-06:00) America/Indiana/Tell_City",
          "UTC(-06:00) America/North_Dakota/Center",
          "UTC(-06:00) America/North_Dakota/New_Salem"
        ]
      }
    },
    { $set: { timezone: "UTC(-06:00) America/Denver" } }
  );



    // Old
  // UTC(-07:00) America/Boise
  // UTC(-07:00) America/Los_Angeles
  // UTC(-07:00) America/Phoenix
  // new
  // UTC(-07:00) America/Los_Angeles

  await User.updateMany(
    { 
      timezone: {
        $in: [
          "UTC(-07:00) America/Boise",
          "UTC(-07:00) America/Los_Angeles",
          "UTC(-07:00) America/Phoenix"
        ]
      }
    },
    { $set: { timezone: "UTC(-07:00) America/Los_Angeles" } }
  );


    // Old
  // UTC(-09:00) America/Adak
  // UTC(-09:00) America/Anchorage
  // UTC(-09:00) America/Juneau
  // UTC(-09:00) America/Metlakatla
  // UTC(-09:00) America/Nome
  // new
  // UTC(-09:00) America/Adak

  await User.updateMany(
    { 
      timezone: {
        $in: [
          "UTC(-09:00) America/Adak",
          "UTC(-09:00) America/Anchorage",
          "UTC(-09:00) America/Juneau",
          "UTC(-09:00) America/Metlakatla",
          "UTC(-09:00) America/Nome"
        ]
      }
    },
    { $set: { timezone: "UTC(-09:00) America/Adak" } }
  );


    // Old
  // UTC(-08:00) America/Anchorage
  // UTC(-08:00) America/Juneau
  // UTC(-08:00) America/Metlakatla
  // UTC(-08:00) America/Nome
  // UTC(-08:00) America/Yakutat
  // new
  // UTC(-08:00) America/Anchorage

  await User.updateMany(
    { 
      timezone: {
        $in: [
          "UTC(-08:00) America/Anchorage",
          "UTC(-08:00) America/Juneau",
          "UTC(-08:00) America/Metlakatla",
          "UTC(-08:00) America/Nome",
          "UTC(-08:00) America/Yakutat"
        ]
      }
    },
    { $set: { timezone: "UTC(-08:00) America/Anchorage" } }
  );


    // Old
  // UTC(-10:00) America/Adak
  // UTC(-10:00) Pacific/Honolulu
  // new
  // UTC(-10:00) Pacific/Honolulu

  await User.updateMany(
    { 
      timezone: {
        $in: [
          "UTC(-10:00) America/Adak",
          "UTC(-10:00) Pacific/Honolulu"
        ]
      }
    },
    { $set: { timezone: "UTC(-10:00) Pacific/Honolulu" } }
  );



Auth Models:
testAccount: z.boolean().default(false),
  browserFingerPrint: z.object({
    fingerPrint: z.number().optional(),
    date: z.string().optional(),
  }),
Associated Context
Type Code Snippet ( .js )
Associated Tags mongodb Find By ID updateOne - Updating a user document all - Resolving multiple promises concurrently mongoose Message Response API Use Cases get - HTTP GET request handler findById - Finding a user by their ID sequelize.js node.js map - Iterating over an array of users $exists - Checking for the existence of a field in a document Asynchronous Programming $select - Selecting specific fields to return in the query result node-mysql Update One find - Querying the User collection Framework:Express.js Sparkles and Unicorn Face JavaScript SDK User Model reactjs Data Retrieval
💡 Smart Description This code snippet defines a route handler for the root URL ("/") of an app. It retrieves a list of users who do not have a certain field, performs some operations on each user, and then sends a JSON response with a message.
This code retrieves a list of users by their ID and updates it with the user's attributes. It then sends an error message to Railbow, but returns JSON response indicating that there is no matching User object or something else if not already exists
🔎 Suggested Searches ExpressJS async await user find updateOne
How to update multiple documents in MongoDB using async await
all example with async await
How to select specific fields in Mongoose find query
all
How to update a single user in Flutter using JavaScript?
How to find an object in Flutter with User and UpdateOne method ?
What is the syntax for updating a specific value in Flutter ?
how to use MessageResponse as you can get data from a web page
Related Links https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
https://mongoosejs.com/docs/api.html#model_Model-updateOne
https://developer.mozilla.org/en-US/docs/Web/API/FormData
https://mongoosejs.com/docs/api.html#model_Model-select
https://mongoosejs.com/docs/api.html#model_Model-map
https://mongoosejs.com/docs/api.html#model_Model.find
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
https://developer.mozilla.org/en-US/docs/Web/API/File
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat
https://www.freecodecamp.org/news/javascript-array-of-objects-tutorial-how-to-create-update-and-loop-through-objects-using-js-array-methods/
https://developer.mozilla.org/en-US/docs/Web/API/notification
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length
https://www.freecodecamp.org/news/javascript-callback-functions-what-are-callbacks-in-js-and-how-to-use-them/
https://reactjs.org/docs/hooks-reference.html#usecallback
Related People Sumanta Kabiraj
Sensitive Information No Sensitive Information Detected
Shareable Link https://sumanta.pieces.cloud/?p=59ae4cad0f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment