Rubiks
Rubiks

Reputation: 481

mongo db using fields that begin with numeric values

I am working on a project that uses mongo db. I am trying to do a comparison between two fields, 2016rank and 2015rank, respectively. I would like it to return the results where the 2016 rank has improved over the 2015 rank.

This is what I wrote to do it.

db.Car_Dealership.find( {$where : function() {return this.2016rank > this.2015rank}}); 

I receive an error when I do this. "identifier starts immediately after numeric literal" and I know exactly why. It is because my rank fields begin with numerical values. Is the only solution to rename the fields?

Upvotes: 0

Views: 67

Answers (1)

Joe
Joe

Reputation: 28376

You could try using bracket notation instead of dot notation:

db.Car_Dealership.find( {$where : function() {return this["2016rank"] > this["2015rank"]}});

Upvotes: 1

Related Questions