✌️
This commit is contained in:
parent
a6c2b4a39f
commit
52d0f3a600
1 changed files with 40 additions and 0 deletions
40
cli/delete-invalid-users.js
Normal file
40
cli/delete-invalid-users.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
const { default: User, deleteUser } = require('../built/models/user');
|
||||
const { default: zip } = require('@prezzemolo/zip')
|
||||
|
||||
const migrate = async (user) => {
|
||||
try {
|
||||
await deleteUser(user._id);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const count = await User.count({
|
||||
uri: /#/
|
||||
});
|
||||
|
||||
const dop = 1
|
||||
const idop = ((count - (count % dop)) / dop) + 1
|
||||
|
||||
return zip(
|
||||
1,
|
||||
async (time) => {
|
||||
console.log(`${time} / ${idop}`)
|
||||
const doc = await User.find({
|
||||
uri: /#/
|
||||
}, {
|
||||
limit: dop, skip: time * dop
|
||||
})
|
||||
return Promise.all(doc.map(migrate))
|
||||
},
|
||||
idop
|
||||
).then(a => {
|
||||
const rv = []
|
||||
a.forEach(e => rv.push(...e))
|
||||
return rv
|
||||
})
|
||||
}
|
||||
|
||||
main().then(console.dir).catch(console.error)
|
Loading…
Reference in a new issue