Skip to content

Instantly share code, notes, and snippets.

@coindegen
Created September 28, 2022 14:46
Show Gist options
  • Save coindegen/0f15268a4e248a14bb9f5e5df5a3a045 to your computer and use it in GitHub Desktop.
Save coindegen/0f15268a4e248a14bb9f5e5df5a3a045 to your computer and use it in GitHub Desktop.
replace address with checksum version
import { ethers } from "ethers"
import { MongoClient } from "mongodb"
require("dotenv-safe").config()
const DATABASE_URI = process.env.DATABASE_URI || ""
const DATABASE_NAME = process.env.DATABASE_NAME
async function main() {
try {
let client = new MongoClient(DATABASE_URI)
await client.connect()
let db = client.db(DATABASE_NAME)
const collection = db.collection("Users")
const res = await collection
.find({}, { sort: { joined_time: 1 }, skip: 3100 })
.limit(1000)
.toArray()
console.log({ res })
let i = 0
for (const affiliate of res) {
const filter = { _id: affiliate._id }
const updateDocument = {
$set: {
address: ethers.utils.getAddress(affiliate.address),
},
}
const result = await collection.updateOne(filter, updateDocument)
if (result.modifiedCount > 0) {
i++
console.log(i)
}
}
console.log("\nDone")
console.log(`Total docs modified: ${i}\n`)
process.exit(0)
} catch (e) {
console.log(e)
}
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment