firebase / firebase/firebase-js-sdk

FR: Expose DocumentReference.create on Web

Open
#6,707 1 comment 0 reactions 1 assignee Claimed by @dconeybe View on GitHub
api: firestore feature request
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

I would like to create a document from the browser using behaviour similar to `O_CREAT | O_EXCL`. [8 other people are also looking for a clean way to do this](https://stackoverflow.com/q/59989973/10477326). This functionality is present in the REST API, it's just not exposed to the JavaScript SDK.

This differs from #1795 in that I'm not using any testing or admin SDK. They found a workaround. I also found a workaround, but I am creating this feature request because that workaround feels like a code smell.

### [REQUIRED] Describe your environment

* Operating System version: (documentation; I haven't downloaded any code yet)
* Browser version: (documentation)
* Firebase SDK version: Javascript - version 9 and Javascript - version 8
* Firebase Product: Firestore

### [REQUIRED] Describe the problem

- The underlying REST API supports this: https://firebase.google.com/docs/firestore/reference/rest/v1/projects.databases.documents/createDocument
- The NodeJS API supports this: https://googleapis.dev/nodejs/firestore/latest/DocumentReference.html#create
- 6 people are confused why only the Web API lacks this: https://stackoverflow.com/questions/46597327/difference-between-firestore-set-with-merge-true-and-update#comment80153511_46600599
- I do not like the workaround that relies on security rules
- I do not like just ignoring this and having to worry about the potential of a race condition
- Whenever underlying capability exists but is hidden, a workaround is not the best solution. Furthermore, the 4 perfect letters of CRUD are cut short into just 3 letters RUD.

#### Steps to reproduce:

1. Open https://firebase.google.com/docs/reference/js/firestore_.documentreference
2. https://firebase.google.com/docs/reference/js/v8/firebase.firestore.DocumentReference
3. CTRL-F for "create"
4. Find no actual "create" method

#### Relevant Code:

This problem is apparent at the documentation level, not the code level.

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.