Search between two values

Asked

Viewed 69 times

0

Well I need to do a search on a collection where I have XI, XF, YI e YF I will send for example x:10, y:9 so I need to identify which location items satisfy that location.

Given the items saved in the bank:

[{
  XI: 1,
  XF: 5,
  YI: 5,
  YF: 20
},
{
  XI: 6,
  XF: 11,
  YI: 21,
  YF: 36
},
{
  XI: 16,
  XF: 21,
  YI: 37,
  YF: 52
},
{
  XI: 22,
  XF: 27,
  YI: 53,
  YF: 68
},
{
  XI: 28,
  XF: 33,
  YI: 69,
  YF: 84
},
{
  XI: 34,
  XF: 39,
  YI: 85,
  YF: 100
}]

I tried to do it this way:

locais.find({
$and: [
  {
    XI: { $gte: 10 },
  },
  {
    XF: { $lte: 10 },
  },
  {
    YI: { $gte: 12 },
  },
  {
    YF: { $lte: 12 },
  },
]
}).then((teste) => {
  console.log(teste)
});

});

But so he’s going to the bank and taking the bank’s values that he’s the number that I told him about.

1 answer

0

My mistake was in the logic I was using,

XI <= meu_numero >= XF

This would be the logic that should be used. And for that I needed to exchange the orders of $gte and $lte

Browser other questions tagged

You are not signed in. Login or sign up in order to post.