Mongodb update field based on another field at a specific time (mongoose)

37
April 12, 2021, at 4:10 PM

As the title suggests I want a field to be updated automatically at a specific time based on another field. For example, we have the following schema:

const exampleSchema = new mongoose.Schema({
  date: [{
    type: Date,
    required: true,
    default: Date.now(),
  }],
  var: {
    type: Number,
    required: true,
    default: 0,
  }
});

I want to update the field var decreasing its value when an element from the array date passes 2 hours after inserting it. Let's say I insert a date now in the array date, I want 2 hours from now on the variable var to automatically decrease his value and at the same time erase the element inserted in date.

READ ALSO
SpringBoot + Thymeleaf + SQL, display HTML table from database

SpringBoot + Thymeleaf + SQL, display HTML table from database

I want to create siteI have already configured login "/login" and registration "/registration" pages

56
How to use elasticsearch rangequery to find values that are less than or equal to a number value in Java API

How to use elasticsearch rangequery to find values that are less than or equal to a number value in Java API

Hello I'm new to Elastic Search and I'm trying to build an elastic search query using Java APII have the following

70
How to save agora stream in Android?

How to save agora stream in Android?

I am using agora sdk for streamingI want to save the stream in agora cloud

68