0

Im having the following schema:

var lottary = new Schema({
    userid : String,
    start: Number,
    end: Number,
    time: Number,
});

and im writing a query that get the result of the winner. if the rows are as follows:

| start | end |
|  2    |  4  |
|   5   | 99  |
| 100   | 999 |

and my number are 55, it would return the row with start 5, and end 99, cause 55 is between those numbers.

I know this are done with the following in MYSQL:

SELECT *
FROM lotto_tickets
WHERE 40 BETWEEN start AND end

But, how is this done within mongoose / mongodb?

Community
  • 1
  • 1
maria
  • 207
  • 5
  • 22
  • 56

1 Answers1

2

Possible duplicate, take a look at this: How to find documents having a query-value within the range of two key-values

db.lottary.find({ "start": { "$lt": 55}, "end": { "$gt": 55}});

You can obviously change the number 55 to anything u want.

Mikey
  • 6,728
  • 4
  • 22
  • 45