antoniopresto / react-native-local-mongodb

react-native local mongodb storage.
MIT License
304 stars 66 forks source link

Support for Date type #62

Closed atulmy closed 4 years ago

atulmy commented 5 years ago

$lt, $lte, $gt and $gte work on numbers and strings

Does it mean these operators will not work with Date field?

Also sort on field with type Date does not seem to work.

nuvolarmobileteam commented 5 years ago

I am new using this library. I have an example where dates are working as expected:

This filters the objects properly: db.find({ date: { $gte: new Date('2004-05-21T09:00:00.000+0000') } }).exec(function (err, docs) {});

This sorts all objects as expected: db.find({}).sort({ date: 1 }).exec(function (err, docs) {});

This inverts the sorting: db.find({}).sort({ date: -1 }).exec(function (err, docs) {});

atulmy commented 5 years ago

@nuvolarmobileteam not sure, I tried same and it did not sort properly. I resorted to saving date in unix timestamp as integer.

antoniopresto commented 5 years ago

For now I would advise you to look for this problem in the nedb library, this package is a clone of it.

nuvolarmobileteam commented 5 years ago

Looks like Date() is the way to go: https://github.com/louischatriot/nedb/issues/383