Coder Social home page Coder Social logo

Comments (4)

suztomo avatar suztomo commented on July 23, 2024

But sometimes there isn't a meaningful ID for the document, and it's more convenient to let Cloud Firestore auto-generate an ID for you. You can do this by calling add()

https://firebase.google.com/docs/firestore/manage-data/add-data

from fake_cloud_firestore.

atn832 avatar atn832 commented on July 23, 2024

You're right, a semi-random id is created in one of two cases:

  1. collectionRef.add(): already roughly supported at https://github.com/atn832/cloud_firestore_mocks/blob/878187ec0d94c26f921196b4f53317305db781f4/lib/src/mock_collection_reference.dart#L43
  2. collectionRef.document(): not supported yet

https://pub.dev/documentation/cloud_firestore/latest/cloud_firestore/CollectionReference/document.html:

DocumentReference document (
[String path]
)
If no path is provided, an auto-generated ID is used.

To fix this issue, we should make it so that mockCollectionRef.document() generates some ID, then returns a MockDocumentRef for that ID, perhaps something like:

  @override
  DocumentReference document([String path]) {
    if (path == null) {
      path = // make some id
    }
    return MockDocumentReference(path, getSubpath(root, path), root,
        getSubpath(snapshotStreamControllerRoot, path));
  }

Do you have such a use case in your projects? I have never run into it because I always use add().

from fake_cloud_firestore.

suztomo avatar suztomo commented on July 23, 2024

The test case reflects my use case. I don’t call “add” when setData is enough.

While it’s feasible to change my code, I prefer cloud_firestore_mocks behaves the same as real firestore as much as possible.

Memo:

Screen Shot 2020-02-25 at 5 29 51 PM

The random key (e.g., 0XZfFoJICLrYBtIQqCHP) contains 20-characters. Number, a-z, A-Z

from fake_cloud_firestore.

suztomo avatar suztomo commented on July 23, 2024

In real Firestore, document('nonexistent key').get returns a future of documentSnapshot but the document is not in Firebase Database.

    final x = await _personsCollection.document('nonexistentkey').get();

Screen Shot 2020-02-25 at 7 16 45 PM

Without specifying documentId, document().get() returns the same. Note that in both cases, 'exists' fields are false.

Screen Shot 2020-02-25 at 7 22 29 PM

from fake_cloud_firestore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.