Created
October 13, 2016 07:56
-
-
Save SimonSimCity/ab633f7f6e7fadbe3eb8d609a4ee42f6 to your computer and use it in GitHub Desktop.
Rewrite all your UUIDs, that accidentially have been saved as BinData(3, "") as BinData(4, ""). But be careful! This script only takes one implementation of the three (Python, Java, C#) and treats all BinData(3, "") datasets like that. This can damage your data if you don't know what you're doing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load this script: https://github.com/mongodb/mongo-csharp-driver/blob/master/uuidhelpers.js | |
// Start your mongo-shell with this script: mongo --shell uuidhelpers.js | |
// Find out what type of UUID it was. In my case it was PYUUID(). But it could (in your case) also be CSUUID() or JUUID(). | |
db.tests.find(function() { return this.orderId.subtype() == 3 }).snapshot().forEach(function(elem) { | |
db.tests.update( | |
{ | |
_id: elem._id | |
}, | |
{ | |
$set: { | |
orderId: UUID(elem.orderId.toPYUUID().substr(8,36).replace(/-/g,"")) | |
} | |
} | |
) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment