Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 904
Siva Sai Avatar asked Oct 12 '16 09:10

Siva Sai


1 Answers

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.

like image 168
Erik Avatar answered Oct 05 '22 22:10

Erik