Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SimonSimCity/ab633f7f6e7fadbe3eb8d609a4ee42f6 to your computer and use it in GitHub Desktop.
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.
// 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