Skip to content

id field value is override by vuefire #1472

Closed as not planned
Closed as not planned
@tlserver

Description

@tlserver

Reproduction

Please see step 2

Steps to reproduce the bug

  1. Create a document in firestore that contain a field named id such as
{
    "id": "123",
    "name": "test document"
}
  1. Read the document via vuefire and print it out
import {doc, getFirestore} from 'firebase/firestore';

const firestore = getFirestore();
const docStm = useDocument(doc(firestore, 'AnyCol/AnyDoc'));
watch(docStm, console.log, {immediate: true});
  1. Check the console
{
    "id": "AnyDoc",
    "name": "test document"
}

Expected behavior

id should be 123

Actual behavior

id is overrided to document ID (AnyDoc)

Additional information

It is good for vuefire to provide access to document id but I think it should not use a normal field name id, since it is a valid field name for firestore too. Use a special field name such as .id can avoid conflict with document data.
One constraint about the firestore document field name is 'not start with a dot(.)'.
image

Also, as suggested in #180, I think the following properties should be exposed to the vuefire data object as non-enumerable properties:

  1. the snapshot itself (optional, better if provided)
  2. all properties(id, metadata, ref) of document snapshot
  3. some properties(metadata, queery) of query snapshot

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions