couchbase_lite icon indicating copy to clipboard operation
couchbase_lite copied to clipboard

Get the document It within the response

Open richard457 opened this issue 3 years ago • 5 comments

When Creating a document the system creates a document ID this ID can be used to update a document, later on, the problem is that there is no way we can get this ID when querying the document. What do you think if the document is returned with the ID?

richard457 avatar Oct 08 '20 10:10 richard457

Again I was assuming that creating a document and passing id as a field with override the system generated ID but that is not the case

final MutableDocument mutableDoc = MutableDocument()
        .setDouble('openingFloat', openingFloat)
        .setDouble('closingFloat', closingFloat)
        .setList('channels', [userId])
        .setString('id', Uuid().v1())
        .setString('_id', userId)
        .setString('tableName', 'drawer_history_' + businessId);
    try {
      await AppDatabase.instance.database.saveDocument(mutableDoc);
    } on PlatformException {
      return 'Error saving document';
    }

richard457 avatar Oct 08 '20 10:10 richard457

The only way to specify the document id is through the constructor. You cannot override it or change it through a property. The document id is not mutable.

bawelter avatar Oct 13 '20 14:10 bawelter

The document id is returned through the Document object https://pub.dev/documentation/couchbase_lite/latest/couchbase_lite/Document-class.html and if you want it in a query you query the document meta data.

bawelter avatar Oct 13 '20 14:10 bawelter

Thanks to @bawelter for help.

richard457 avatar Nov 11 '20 22:11 richard457

an example of how to query the document metadata. will be useful @bawelter

richard457 avatar Nov 12 '20 06:11 richard457