mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Add 'endId' parameter to rearchive script
This commit is contained in:
parent
38cc0488b1
commit
0911011624
1 changed files with 17 additions and 5 deletions
|
@ -61,20 +61,32 @@ async function rearchiveAllDocs() {
|
||||||
// start from an objectId and run in ascending order, so we can resume later
|
// start from an objectId and run in ascending order, so we can resume later
|
||||||
const query = {}
|
const query = {}
|
||||||
const startId = params._[0]
|
const startId = params._[0]
|
||||||
|
const endId = params.e
|
||||||
if (startId) {
|
if (startId) {
|
||||||
const validator = new RegExp('^[0-9a-fA-F]{24}$')
|
if (!new RegExp('^[0-9a-fA-F]{24}$').test(startId)) {
|
||||||
if (!validator.test(startId)) {
|
throw new Error('Invalid start object id')
|
||||||
console.error('Invalid object id')
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
query._id = {
|
query._id = {
|
||||||
$gt: ObjectId(startId)
|
$gte: ObjectId(startId)
|
||||||
}
|
}
|
||||||
console.log(`Starting from object ID ${startId}`)
|
console.log(`Starting from object ID ${startId}`)
|
||||||
} else {
|
} else {
|
||||||
console.log('No object id specified. Starting from the beginning.')
|
console.log('No object id specified. Starting from the beginning.')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (endId) {
|
||||||
|
if (!new RegExp('^[0-9a-fA-F]{24}$').test(endId)) {
|
||||||
|
throw new Error('Invalid end object id')
|
||||||
|
}
|
||||||
|
query._id = {
|
||||||
|
...(query._id || {}),
|
||||||
|
...{
|
||||||
|
$lte: ObjectId(endId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(`Stopping at object ID ${endId}`)
|
||||||
|
}
|
||||||
|
|
||||||
const results = (await getCollection('projects'))
|
const results = (await getCollection('projects'))
|
||||||
.find(query, { _id: 1 })
|
.find(query, { _id: 1 })
|
||||||
.sort({ _id: 1 })
|
.sort({ _id: 1 })
|
||||||
|
|
Loading…
Reference in a new issue