Comments (4)
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.
You're right, a semi-random id is created in one of two cases:
collectionRef.add()
: already roughly supported at https://github.com/atn832/cloud_firestore_mocks/blob/878187ec0d94c26f921196b4f53317305db781f4/lib/src/mock_collection_reference.dart#L43collectionRef.document()
: not supported yet
DocumentReference document (
[String path]
)
If nopath
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.
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:
The random key (e.g., 0XZfFoJICLrYBtIQqCHP
) contains 20-characters. Number, a-z, A-Z
from fake_cloud_firestore.
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();
Without specifying documentId, document().get()
returns the same. Note that in both cases, 'exists' fields are false.
from fake_cloud_firestore.
Related Issues (20)
- Support for flutter web HOT 1
- mergeFields ignored in mock "set" method HOT 2
- Batch failure is different compared to real firestore
- Transaction does not revert if an error occurs HOT 1
- Cannot throw exception on DocumentReference.get() call (#get) HOT 1
- Please update dependancies HOT 3
- Throwing exceptions with Queries do not work when using different references
- Collection.get does not support throwing Exceptions
- StreamSubscription<QuerySnapshot<Map<String, dynamic>>> fails to capture data if the query is filtered using .where(field, arrayContains: Map<String, String>)
- type 'MethodChannelFieldValue' is not a subtype of type 'MockFieldValuePlatform' in type cast HOT 1
- add option to dump/load database to/from file HOT 1
- Add support for `cloud_firestore: ^4.14.0` HOT 5
- Support for Firestore OR queries HOT 2
- listeners not updating with #284 fix
- Error with type mismatch in Query.startAt
- throws null value with composite key query on null data document HOT 1
- Cannot use `whereIn` operator on map
- Stream is not updated when using map
- Add `pauseNetwork`, `unpauseNetwork`, `stopNetwork`
- Fix incompatibility with cloud_firestore 4.17.0 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fake_cloud_firestore.