firestore-batch-updater 1.15.0 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.ko.md CHANGED
@@ -31,6 +31,7 @@
31
31
  - 그룹별 개수 조회 - `countBy()`로 특정 필드 값별 문서 수 집계
32
32
  - 랜덤 샘플링 - `sample()`로 쿼리 결과에서 랜덤 문서 추출
33
33
  - 필드 값 추출 - `pluck()`로 특정 필드 값만 간단하게 배열로 추출
34
+ - 문서 ID 추출 - `pluckIds()`로 매칭 문서의 ID만 배열로 추출
34
35
  - FieldValue 지원 - `increment()`, `arrayUnion()`, `delete()`, `serverTimestamp()` 등 사용 가능
35
36
  - 서브컬렉션 & 컬렉션 그룹 - 서브컬렉션 쿼리 또는 동일 이름의 모든 컬렉션 쿼리
36
37
  - Dry Run 모드 - 실제 변경 없이 작업 시뮬레이션
@@ -129,6 +130,7 @@ console.log(`${result.successCount}개 문서 업데이트 완료`);
129
130
  | `distinct(field)` | 특정 필드의 고유값 조회 | `any[]` |
130
131
  | `sample(n)` | 매칭 문서에서 랜덤 샘플 추출 | `{ id, data }[]` |
131
132
  | `pluck(field)` | 특정 필드 값만 배열로 추출 | `any[]` |
133
+ | `pluckIds()` | 매칭 문서의 ID만 배열로 추출 | `string[]` |
132
134
  | `toJSON(path, options?)` | 문서를 JSON 파일로 내보내기 | `ToJSONResult` |
133
135
  | `fromJSON(path, options?)` | JSON 파일에서 문서 가져오기 | `FromJSONResult` |
134
136
  | `countBy(field)` | 필드 값별 문서 수 집계 | `CountByResult` |
@@ -827,6 +829,32 @@ const countries = await updater.collection("users").pluck("address.country");
827
829
  // ["US", "KR", "JP", ...]
828
830
  ```
829
831
 
832
+ ### 문서 ID 추출
833
+
834
+ ```typescript
835
+ // 매칭 문서의 ID만 배열로 추출
836
+ const inactiveIds = await updater
837
+ .collection("users")
838
+ .where("status", "==", "inactive")
839
+ .pluckIds();
840
+ console.log(inactiveIds); // ["user-1", "user-3", ...]
841
+
842
+ // bulkDelete/bulkUpdate와 체이닝하여 효율적 처리
843
+ const expiredIds = await updater
844
+ .collection("sessions")
845
+ .where("expiresAt", "<", new Date())
846
+ .pluckIds();
847
+
848
+ await updater.collection("sessions").bulkDelete(expiredIds);
849
+
850
+ // limit, orderBy와 함께 사용 가능
851
+ const topIds = await updater
852
+ .collection("users")
853
+ .orderBy("score", "desc")
854
+ .limit(10)
855
+ .pluckIds();
856
+ ```
857
+
830
858
  ### 랜덤 샘플링
831
859
 
832
860
  ```typescript
package/README.md CHANGED
@@ -31,6 +31,7 @@ English | [한국어](./README.ko.md)
31
31
  - Group counting - Use `countBy()` to count documents grouped by field value
32
32
  - Random sampling - Use `sample()` to get random documents from query results
33
33
  - Field value extraction - Use `pluck()` to get a simple array of field values
34
+ - Document ID extraction - Use `pluckIds()` to get an array of matching document IDs
34
35
  - FieldValue support - Use `increment()`, `arrayUnion()`, `delete()`, `serverTimestamp()`, etc.
35
36
  - Subcollection & Collection Group - Query subcollections or all collections with the same name
36
37
  - Dry run mode - Simulate operations without making changes
@@ -129,6 +130,7 @@ console.log(`Updated ${result.successCount} documents`);
129
130
  | `distinct(field)` | Get unique values of a field | `any[]` |
130
131
  | `sample(n)` | Get random sample of matching documents | `{ id, data }[]` |
131
132
  | `pluck(field)` | Get array of values for a specific field | `any[]` |
133
+ | `pluckIds()` | Get array of matching document IDs | `string[]` |
132
134
  | `toJSON(path, options?)` | Export documents to JSON file | `ToJSONResult` |
133
135
  | `fromJSON(path, options?)` | Import documents from JSON file | `FromJSONResult` |
134
136
  | `countBy(field)` | Count documents grouped by field value | `CountByResult` |
@@ -840,6 +842,32 @@ const countries = await updater.collection("users").pluck("address.country");
840
842
  // ["US", "KR", "JP", ...]
841
843
  ```
842
844
 
845
+ ### Pluck Document IDs
846
+
847
+ ```typescript
848
+ // Get all matching document IDs as an array
849
+ const inactiveIds = await updater
850
+ .collection("users")
851
+ .where("status", "==", "inactive")
852
+ .pluckIds();
853
+ console.log(inactiveIds); // ["user-1", "user-3", ...]
854
+
855
+ // Chain with bulk operations for efficient workflows
856
+ const expiredIds = await updater
857
+ .collection("sessions")
858
+ .where("expiresAt", "<", new Date())
859
+ .pluckIds();
860
+
861
+ await updater.collection("sessions").bulkDelete(expiredIds);
862
+
863
+ // Works with limit() and orderBy()
864
+ const topIds = await updater
865
+ .collection("users")
866
+ .orderBy("score", "desc")
867
+ .limit(10)
868
+ .pluckIds();
869
+ ```
870
+
843
871
  ### Random Sampling
844
872
 
845
873
  ```typescript
package/dist/index.d.mts CHANGED
@@ -703,6 +703,12 @@ declare class BatchUpdater {
703
703
  * @returns Array of field values (null/undefined values are excluded)
704
704
  */
705
705
  pluck(field: string): Promise<any[]>;
706
+ /**
707
+ * Get an array of document IDs from matching documents
708
+ * Useful for passing IDs directly to bulkUpdate(), bulkDelete(), etc.
709
+ * @returns Array of document IDs
710
+ */
711
+ pluckIds(): Promise<string[]>;
706
712
  /**
707
713
  * Create multiple documents in batch
708
714
  * Note: This method does not work with collectionGroup()
package/dist/index.d.ts CHANGED
@@ -703,6 +703,12 @@ declare class BatchUpdater {
703
703
  * @returns Array of field values (null/undefined values are excluded)
704
704
  */
705
705
  pluck(field: string): Promise<any[]>;
706
+ /**
707
+ * Get an array of document IDs from matching documents
708
+ * Useful for passing IDs directly to bulkUpdate(), bulkDelete(), etc.
709
+ * @returns Array of document IDs
710
+ */
711
+ pluckIds(): Promise<string[]>;
706
712
  /**
707
713
  * Create multiple documents in batch
708
714
  * Note: This method does not work with collectionGroup()
package/dist/index.js CHANGED
@@ -794,6 +794,17 @@ var BatchUpdater = class {
794
794
  }
795
795
  return values;
796
796
  }
797
+ /**
798
+ * Get an array of document IDs from matching documents
799
+ * Useful for passing IDs directly to bulkUpdate(), bulkDelete(), etc.
800
+ * @returns Array of document IDs
801
+ */
802
+ async pluckIds() {
803
+ this.validateSetup();
804
+ const query = this.buildQuery();
805
+ const snapshot = await query.get();
806
+ return snapshot.docs.map((doc) => doc.id);
807
+ }
797
808
  /**
798
809
  * Create multiple documents in batch
799
810
  * Note: This method does not work with collectionGroup()
package/dist/index.mjs CHANGED
@@ -749,6 +749,17 @@ var BatchUpdater = class {
749
749
  }
750
750
  return values;
751
751
  }
752
+ /**
753
+ * Get an array of document IDs from matching documents
754
+ * Useful for passing IDs directly to bulkUpdate(), bulkDelete(), etc.
755
+ * @returns Array of document IDs
756
+ */
757
+ async pluckIds() {
758
+ this.validateSetup();
759
+ const query = this.buildQuery();
760
+ const snapshot = await query.get();
761
+ return snapshot.docs.map((doc) => doc.id);
762
+ }
752
763
  /**
753
764
  * Create multiple documents in batch
754
765
  * Note: This method does not work with collectionGroup()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firestore-batch-updater",
3
- "version": "1.15.0",
3
+ "version": "1.16.0",
4
4
  "description": "Batch update Firestore documents with query-based filtering and preview",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",