firestore-batch-updater 1.13.0 → 1.14.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 +21 -0
- package/README.md +21 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +22 -0
- package/dist/index.mjs +22 -0
- package/package.json +1 -1
package/README.ko.md
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
- JSON 내보내기/가져오기 - `toJSON()` / `fromJSON()`으로 문서 JSON 파일 내보내기/가져오기
|
|
31
31
|
- 그룹별 개수 조회 - `countBy()`로 특정 필드 값별 문서 수 집계
|
|
32
32
|
- 랜덤 샘플링 - `sample()`로 쿼리 결과에서 랜덤 문서 추출
|
|
33
|
+
- 필드 값 추출 - `pluck()`로 특정 필드 값만 간단하게 배열로 추출
|
|
33
34
|
- FieldValue 지원 - `increment()`, `arrayUnion()`, `delete()`, `serverTimestamp()` 등 사용 가능
|
|
34
35
|
- 서브컬렉션 & 컬렉션 그룹 - 서브컬렉션 쿼리 또는 동일 이름의 모든 컬렉션 쿼리
|
|
35
36
|
- Dry Run 모드 - 실제 변경 없이 작업 시뮬레이션
|
|
@@ -125,6 +126,7 @@ console.log(`${result.successCount}개 문서 업데이트 완료`);
|
|
|
125
126
|
| `copyTo(target, options?)` | 다른 컬렉션으로 문서 복사/이동 | `CopyToResult` |
|
|
126
127
|
| `distinct(field)` | 특정 필드의 고유값 조회 | `any[]` |
|
|
127
128
|
| `sample(n)` | 매칭 문서에서 랜덤 샘플 추출 | `{ id, data }[]` |
|
|
129
|
+
| `pluck(field)` | 특정 필드 값만 배열로 추출 | `any[]` |
|
|
128
130
|
| `toJSON(path, options?)` | 문서를 JSON 파일로 내보내기 | `ToJSONResult` |
|
|
129
131
|
| `fromJSON(path, options?)` | JSON 파일에서 문서 가져오기 | `FromJSONResult` |
|
|
130
132
|
| `countBy(field)` | 필드 값별 문서 수 집계 | `CountByResult` |
|
|
@@ -781,6 +783,25 @@ await updater.collection("users").toJSON("./backup.json");
|
|
|
781
783
|
await updater.collection("users_backup").fromJSON("./backup.json");
|
|
782
784
|
```
|
|
783
785
|
|
|
786
|
+
### 필드 값 추출
|
|
787
|
+
|
|
788
|
+
```typescript
|
|
789
|
+
// 이메일 값만 간단한 배열로 추출
|
|
790
|
+
const emails = await updater
|
|
791
|
+
.collection("users")
|
|
792
|
+
.where("status", "==", "active")
|
|
793
|
+
.pluck("email");
|
|
794
|
+
console.log(emails); // ["alice@test.com", "bob@test.com", ...]
|
|
795
|
+
|
|
796
|
+
// 가격 값 추출 후 계산
|
|
797
|
+
const prices = await updater.collection("products").pluck("price");
|
|
798
|
+
const total = prices.reduce((sum, p) => sum + p, 0);
|
|
799
|
+
|
|
800
|
+
// 중첩 필드 지원
|
|
801
|
+
const countries = await updater.collection("users").pluck("address.country");
|
|
802
|
+
// ["US", "KR", "JP", ...]
|
|
803
|
+
```
|
|
804
|
+
|
|
784
805
|
### 랜덤 샘플링
|
|
785
806
|
|
|
786
807
|
```typescript
|
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ English | [한국어](./README.ko.md)
|
|
|
30
30
|
- JSON export/import - Use `toJSON()` / `fromJSON()` to export/import documents as JSON
|
|
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
|
+
- Field value extraction - Use `pluck()` to get a simple array of field values
|
|
33
34
|
- FieldValue support - Use `increment()`, `arrayUnion()`, `delete()`, `serverTimestamp()`, etc.
|
|
34
35
|
- Subcollection & Collection Group - Query subcollections or all collections with the same name
|
|
35
36
|
- Dry run mode - Simulate operations without making changes
|
|
@@ -125,6 +126,7 @@ console.log(`Updated ${result.successCount} documents`);
|
|
|
125
126
|
| `copyTo(target, options?)` | Copy/move docs to another collection | `CopyToResult` |
|
|
126
127
|
| `distinct(field)` | Get unique values of a field | `any[]` |
|
|
127
128
|
| `sample(n)` | Get random sample of matching documents | `{ id, data }[]` |
|
|
129
|
+
| `pluck(field)` | Get array of values for a specific field | `any[]` |
|
|
128
130
|
| `toJSON(path, options?)` | Export documents to JSON file | `ToJSONResult` |
|
|
129
131
|
| `fromJSON(path, options?)` | Import documents from JSON file | `FromJSONResult` |
|
|
130
132
|
| `countBy(field)` | Count documents grouped by field value | `CountByResult` |
|
|
@@ -794,6 +796,25 @@ await updater.collection("users").toJSON("./backup.json");
|
|
|
794
796
|
await updater.collection("users_backup").fromJSON("./backup.json");
|
|
795
797
|
```
|
|
796
798
|
|
|
799
|
+
### Pluck Field Values
|
|
800
|
+
|
|
801
|
+
```typescript
|
|
802
|
+
// Get just the email values as a simple array
|
|
803
|
+
const emails = await updater
|
|
804
|
+
.collection("users")
|
|
805
|
+
.where("status", "==", "active")
|
|
806
|
+
.pluck("email");
|
|
807
|
+
console.log(emails); // ["alice@test.com", "bob@test.com", ...]
|
|
808
|
+
|
|
809
|
+
// Get prices for calculation
|
|
810
|
+
const prices = await updater.collection("products").pluck("price");
|
|
811
|
+
const total = prices.reduce((sum, p) => sum + p, 0);
|
|
812
|
+
|
|
813
|
+
// Nested field support
|
|
814
|
+
const countries = await updater.collection("users").pluck("address.country");
|
|
815
|
+
// ["US", "KR", "JP", ...]
|
|
816
|
+
```
|
|
817
|
+
|
|
797
818
|
### Random Sampling
|
|
798
819
|
|
|
799
820
|
```typescript
|
package/dist/index.d.mts
CHANGED
|
@@ -682,6 +682,13 @@ declare class BatchUpdater {
|
|
|
682
682
|
* @returns Array of field values with document IDs
|
|
683
683
|
*/
|
|
684
684
|
getFields(fieldPath: string): Promise<FieldValueResult[]>;
|
|
685
|
+
/**
|
|
686
|
+
* Get an array of values for a specific field from matching documents
|
|
687
|
+
* Convenience wrapper around getFields() that returns only values (no IDs)
|
|
688
|
+
* @param field - Field path to extract values from
|
|
689
|
+
* @returns Array of field values (null/undefined values are excluded)
|
|
690
|
+
*/
|
|
691
|
+
pluck(field: string): Promise<any[]>;
|
|
685
692
|
/**
|
|
686
693
|
* Create multiple documents in batch
|
|
687
694
|
* Note: This method does not work with collectionGroup()
|
package/dist/index.d.ts
CHANGED
|
@@ -682,6 +682,13 @@ declare class BatchUpdater {
|
|
|
682
682
|
* @returns Array of field values with document IDs
|
|
683
683
|
*/
|
|
684
684
|
getFields(fieldPath: string): Promise<FieldValueResult[]>;
|
|
685
|
+
/**
|
|
686
|
+
* Get an array of values for a specific field from matching documents
|
|
687
|
+
* Convenience wrapper around getFields() that returns only values (no IDs)
|
|
688
|
+
* @param field - Field path to extract values from
|
|
689
|
+
* @returns Array of field values (null/undefined values are excluded)
|
|
690
|
+
*/
|
|
691
|
+
pluck(field: string): Promise<any[]>;
|
|
685
692
|
/**
|
|
686
693
|
* Create multiple documents in batch
|
|
687
694
|
* Note: This method does not work with collectionGroup()
|
package/dist/index.js
CHANGED
|
@@ -726,6 +726,28 @@ var BatchUpdater = class {
|
|
|
726
726
|
}
|
|
727
727
|
return results;
|
|
728
728
|
}
|
|
729
|
+
/**
|
|
730
|
+
* Get an array of values for a specific field from matching documents
|
|
731
|
+
* Convenience wrapper around getFields() that returns only values (no IDs)
|
|
732
|
+
* @param field - Field path to extract values from
|
|
733
|
+
* @returns Array of field values (null/undefined values are excluded)
|
|
734
|
+
*/
|
|
735
|
+
async pluck(field) {
|
|
736
|
+
this.validateSetup();
|
|
737
|
+
if (!field || typeof field !== "string") {
|
|
738
|
+
throw new Error("Field path is required");
|
|
739
|
+
}
|
|
740
|
+
const query = this.buildQuery();
|
|
741
|
+
const snapshot = await query.get();
|
|
742
|
+
const values = [];
|
|
743
|
+
for (const doc of snapshot.docs) {
|
|
744
|
+
const value = this.getNestedValue(doc.data(), field);
|
|
745
|
+
if (value !== void 0 && value !== null) {
|
|
746
|
+
values.push(value);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
return values;
|
|
750
|
+
}
|
|
729
751
|
/**
|
|
730
752
|
* Create multiple documents in batch
|
|
731
753
|
* Note: This method does not work with collectionGroup()
|
package/dist/index.mjs
CHANGED
|
@@ -681,6 +681,28 @@ var BatchUpdater = class {
|
|
|
681
681
|
}
|
|
682
682
|
return results;
|
|
683
683
|
}
|
|
684
|
+
/**
|
|
685
|
+
* Get an array of values for a specific field from matching documents
|
|
686
|
+
* Convenience wrapper around getFields() that returns only values (no IDs)
|
|
687
|
+
* @param field - Field path to extract values from
|
|
688
|
+
* @returns Array of field values (null/undefined values are excluded)
|
|
689
|
+
*/
|
|
690
|
+
async pluck(field) {
|
|
691
|
+
this.validateSetup();
|
|
692
|
+
if (!field || typeof field !== "string") {
|
|
693
|
+
throw new Error("Field path is required");
|
|
694
|
+
}
|
|
695
|
+
const query = this.buildQuery();
|
|
696
|
+
const snapshot = await query.get();
|
|
697
|
+
const values = [];
|
|
698
|
+
for (const doc of snapshot.docs) {
|
|
699
|
+
const value = this.getNestedValue(doc.data(), field);
|
|
700
|
+
if (value !== void 0 && value !== null) {
|
|
701
|
+
values.push(value);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
return values;
|
|
705
|
+
}
|
|
684
706
|
/**
|
|
685
707
|
* Create multiple documents in batch
|
|
686
708
|
* Note: This method does not work with collectionGroup()
|