File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ import nano from 'nano'
2+
3+ import { config } from '../config'
4+
5+ async function main ( ) : Promise < void > {
6+ const db = nano ( config . couchUri ) . use ( 'db_rates' )
7+ const BATCH_SIZE = 1000
8+
9+ try {
10+ let bookmark : string | undefined
11+ let totalProcessed = 0
12+
13+ while ( true ) {
14+ const result = await db . find ( {
15+ selector : {
16+ _id : {
17+ $gte : '2025-01-14T00:00:00.000Z' ,
18+ $lt : '2025-01-16T19:48:58.038Z'
19+ }
20+ } ,
21+ limit : BATCH_SIZE ,
22+ bookmark
23+ } )
24+
25+ if ( result . docs . length === 0 ) break
26+
27+ console . log ( `Processing batch of ${ result . docs . length } documents` )
28+
29+ for ( const doc of result . docs ) {
30+ try {
31+ // await db.destroy(doc._id, doc._rev)
32+ console . log ( `Deleted document ${ doc . _id } ` )
33+ } catch ( err ) {
34+ console . error ( `Failed to delete document ${ doc . _id } :` , err )
35+ }
36+ }
37+
38+ totalProcessed += result . docs . length
39+ bookmark = result . bookmark
40+ console . log ( `Processed ${ totalProcessed } documents total` )
41+ }
42+
43+ console . log ( `Finished deleting ${ totalProcessed } documents` )
44+ } catch ( err ) {
45+ console . error ( 'Error:' , err )
46+ process . exit ( 1 )
47+ }
48+ }
49+
50+ main ( ) . catch ( console . error )
You can’t perform that action at this time.
0 commit comments