SaltechSystems / couchbase_lite

Flutter plugin for the Community edition of Couchbase Lite. Couchbase Lite is an embedded lightweight, document-oriented (NoSQL), syncable database engine.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get the document It within the response

richard457 opened this issue · 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?

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';
    }

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.

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.

Thanks to @bawelter for help.

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