Mongodb Query for a date range when a date is stored as a string

I save data in bongo as a bulk insert. The data that the JSON object array contains the date, numeric, alphanumeric data, all saved as a string.

Data examples

[{
    "CARDNO": "661",
    "HOLDERNO": "661",
    "HOLDERNAME": "S",
    "IODATE": "4/1/2012",
    "IOTIME": "00:03:27",
    "IOGATENO": "01-3",
    "IOGATENAME": "FWork",
    "IOSTATUS": "Entry",
    "DEPARTMENTNO": "1",
    "UPDATE_STATUS": "1"
}, {
    "CARDNO": "711",
    "HOLDERNO": "711",
    "HOLDERNAME": "P",
    "IODATE": "4/1/2012",
    "IOTIME": "04:35:33",
    "IOGATENO": "01-7",
    "IOGATENAME": "FDWork",
    "IOSTATUS": "Exit",
    "DEPARTMENTNO": "3",
    "UPDATE_STATUS": "1"
}]

My request

var start = new Date (2012, 4, 15); var end = new Date (2012, 4, 1);

collection.find({
    "IODATE": {
        $gte: start,
        $lt: end
    }
}).toArray(function (err, data) {
    if (err) {
        console.log(err);
    } else {
        console.log(data.length)
    }
    //res.send(data.length);
    res.send(JSON.stringify(data));
});

This does not return a result, I think this is because the value "IODATE"is in a string inside db.

How to get around this problem? I may have to do a bulk insert, as the data can be 200 million or so.

+3
source share
1 answer

A past attempt, because you do not have a good record of taking good advice.

, , , . , . :

, , . , . , , :

  • BSON
  • ()
  • ( )

, -, , . , .

+3

All Articles