Add in current timestamp while upsert

Hello, @Rahul_Bansal! Welcome to the community!

You need to calculate your new date at your application level:

var dateToInsert = new Date(
  Date.now() + 2 * 1000
);

db.test1.updateOne(
  {
    privateIp: '<ip>',
  },
  {
    $set: {
      updateTime: dateToInsert,
    }
  },
  {
    upsert: true,
  }
);
2 Likes