Siva Sai
Siva Sai

Reputation: 396

Mongodb greater than query

I have an employee collection like this

Company.            Ceo.       Employees
Sdr.                Siva.      1-200
Datamatica.         Durga.     200-400
Big.                Mouli.     50-100

After using

db.employee.find({Employees : {$gte : 200}}) 

I don't get any data. The Employees field type is a string.

Upvotes: 10

Views: 14989

Answers (1)

Erik
Erik

Reputation: 3048

As japrescott stated, you should split the Employeesfield into two separate fields (employees_from, employees_to) of type Number and then query like this:

db.employee.find({employees_from : {$gte : 200}})

For migration you could use mongo's map reduce to split the current Employees into two separate field and add these to your documents. Afterwards you can delete the Employees field.

Upvotes: 18

Related Questions