firebase / firebase/firebase-tools

firebase_tools.firestore.delete with + sign in the path don't delete

Open
#5,228 5 comments 0 reactions 1 assignee Claimed by @rafikhan View on GitHub
api: firestore help-wanted internal-bug-filed type: bug
Dominant language
TypeScript
Stars
4.5k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
84

Description

### [REQUIRED] Environment info

**firebase-tools:**

11.17

**Platform:**

macOS

### [REQUIRED] Test case

```
const admin = require("firebase-admin");
const firebase_tools = require("firebase-tools");
const FieldValue = admin.firestore.FieldValue;

const serviceAccountFileName = "./[something].json";
const databaseUrl = "https://[something].firebaseio.com";
const storageBucket = "[something].appspot.com";
const project = "[something]";

const serviceAccount = require(serviceAccountFileName);
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: databaseUrl,
storageBucket: storageBucket,
});

const deleteCollection = async function (path) {
await firebase_tools.firestore.delete(path, {
project: project,
recursive: true,
yes: true,
force: true,
});
};

const start = async function () {
const path = "/users/test+test/locationHistory";
const db = admin.firestore();
const ref = db.collection(path);
await ref.add({ timestamp: FieldValue.serverTimestamp() });

const snapshotBefore = await ref.get();
console.log("snapshot before:");
snapshotBefore.forEach((doc) => {
console.log(doc.data());
});

console.log(`delete path: ${path}`);
await deleteCollection(path);

const snapshotAfter = await ref.get();
console.log("snapshot after:");
snapshotAfter.forEach((doc) => {
console.log(doc.data());
});
};

start();

```

### [REQUIRED] Steps to reproduce

1. have a firebase project on your machine
2. create a new file in your firebase functions named test.js and copy/paste the code above
3. replace [something] in the code above with your project name
4. run node test in the terminal
5. notice the output "snapshot after:" still has data
6. remove the + from the path and run it again
7. notice how the "snapshot after" has no data

### [REQUIRED] Expected behavior

It should delete all documents in the locationHistory collection

### [REQUIRED] Actual behavior

It don't delete anything. It fails without error

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.