I'm very new to MongoDB and its queries but at the moment, I can't change a 'column' in a collection from string to date.
My database and collection are both called thdr. I want to change the column 'PSTNG_DATE' to a date format. At the moment the format is '19.10.2017'.
I went through the threads here and tried a couple of stuff, but it doesn't seem to work. I understand that I can either change it through the MongoDB Shell or using PyMongo.
I very much appreciate your help and guidance, thanks a lot.
** UPDATE ** That's what I have at the moment and it gives me the syntax error
db = db.getSiblingDB('thdr');
var requests = [];
db.thdr.find().forEach(doc => {
var date = yourFunctionThatConvertsStringToDate(doc.PSTNG_DATE);
requests.push( {
'updateOne': {
'filter': { '_id': doc._id },
'update': { '$set': {
"PSTNG_DATE": date
} }
}
});
if (requests.length === 500) {
db.thdr.bulkWrite(requests);
requests = [];
}
});
if(requests.length > 0) {
db.thdr.bulkWrite(requests);
}