Search code examples
sequelize.jsfeathersjs

Create a query between two timestamps in feathersjs


How do I create a query in feathersjs where I can find all the rows between two timestamps. I am using mysql as the database.

This is what I have so far:

const moment = require("moment");

...

app
.service("bids")
.find({
  query: {
    rate: "official",
    $and: [
      {
        updatedAt: { $gt: moment().subtract(1, "days").startOf("day") },
        updatedAt: { $lt: moment().subtract(1, "days").endOf("day") },
      },
    ],
  },
})

I'd like to find everything between yesterday's 24hours. I have also tried the $or syntax. Somebody help.


Solution

  • You can apply multiple operators to the same condition:

    app
    .service("bids")
    .find({
      query: {
        rate: "official",
        updatedAt: {
          $gt: moment().subtract(1, "days").startOf("day"),
          $lt: moment().subtract(1, "days").endOf("day")
        }
      },
    })