stupidest shit ever
This commit is contained in:
parent
d7dbe2ccf0
commit
ef832432fd
24
bin/mongodb/study-updatedAt-unfuck.js
Normal file
24
bin/mongodb/study-updatedAt-unfuck.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* [INSERT HEAVY SWEARING HERE]
|
||||
*
|
||||
* there are duplicated keys in mongodb.
|
||||
* "updatedAt":{"$date":"2019-12-13T02:01:26.389Z"},"updatedAt":{"$date":"2019-12-13T02:00:30.324Z"}
|
||||
*
|
||||
* only visible with mongoexport, but cause bugs when used with reactivemongo
|
||||
*/
|
||||
db.study.find().forEach(s1 => {
|
||||
let id = s1._id;
|
||||
let u1 = s1.updatedAt;
|
||||
db.study.update({_id: id},{$unset:{updatedAt:1}});
|
||||
let s2 = db.study.findOne({_id: id});
|
||||
let u2 = s2.updatedAt;
|
||||
let u3;
|
||||
if (u2) {
|
||||
let newer = u1 > u2 ? 'first' : 'second';
|
||||
print(`Found duplicated updatedAt for ${id}, ${newer} one is newer`);
|
||||
db.study.update({_id: id},{$unset:{updatedAt:1}});
|
||||
u3 = u1 > u2 ? u1 : u2;
|
||||
} else {
|
||||
u3 = u1;
|
||||
}
|
||||
db.study.update({_id: id},{$set:{updatedAt: u3}});
|
||||
});
|
Loading…
Reference in a new issue