0

I want to select all the documents in a collection that have 'age' property greater than a given age value.

Not working,

age: {
    $gt: given_age_value
}

Working fine,

age: {
    $gt: +given_age_value
}

What difference does the plus sign make? I can't find it in docs.

Jankapunkt
  • 8,128
  • 4
  • 30
  • 59
Sid24
  • 334
  • 3
  • 14
  • the + sign converts **given_age_value** (if it's something other than a valid number) to a number – taha Jul 04 '17 at 09:00

1 Answers1

1

because the given_age_value is not a number (string may be) and adding + before makes it to a number.

{$gt: "1"} doesn't work

{$gt: 1} will work

{$gt: +"1"} will work

Fetrarij
  • 7,176
  • 3
  • 27
  • 35