Question regarding Document update and save to server

Hi,

I want to clarify whether the below code is fine or anything wrong in that.

I have iOS client and Couchbase server installed. I am updating some data on the client. I am referring GrocerySync iOS sample, which has UITableview and displaying the list of document.
I have further modified and updating the document on the iOS app and send the updated document to server using the below code,

  • (IBAction)updateDocument:(id)sender {

    CBLQueryRow *row = [dataSource rowAtIndex:selectedTableRow];
    CBLDocument *doc = row.document;

    NSError* error;
    CBLSavedRevision* newRev = [doc update:^BOOL(CBLUnsavedRevision *rev) {

      rev[@“studentID"] = self->studentIDFld.text;
      rev[@“studentName"] = self->studentNameFld.text;
      rev[@“teacherName"] = self->teacherNameFld.text;
      rev[@"description"] = self->descriptionTxtView.text;
      rev[@“fees”] = self->feesAmtFld.text;
      rev[@“deviceuser"] = self->deviceuserFld.text;
      
      return YES;
    

    } error: &error];

    if (!newRev) {
    UIAlertView* error = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@“Alert”,nil)
    message:NSLocalizedString(@“Failed to update item.”,nil)
    delegate:nil
    cancelButtonTitle:NSLocalizedString(@“Ok”,nil)
    otherButtonTitles:nil ,nil];

      [error show];
    

    }

}

This is pushing updated data to server without any issues. I do have push, pull and continuos replication observor sync code in iOS app.

My question is, is this way we have to manually update the data from client app to server? Because, whatever I am updating on the server side, it is getting automatically reflected on the iOS app, i didn’t do any manual insert. But, when I update the data from iOS app, Do I need to call “update” API and manually update the document data like this for each field → (rev[@“studentID"] = self->studentIDFld.text;) ?

Yes, that code shows how to update a document in the local database.

Don’t think of this code as updating the server. It doesn’t do that, not directly. All it does is save a change to your local database. The replicator is a separate component of Couchbase Lite that finds new local changes and uploads them to the server.

I have a question. As I said I follow GrocerySync iOS sample. I am having the following code to create document on the iOS app. This is working pretty well. My question is, Couchbase lite supports JSON and Object storage. The way doing below is JSON based or Object storage based?

NSDictionary *document = @{@“Text”: text,
@“studentID”: @“Stud1”,
@“studentName”: @“JonG”,
@“teacherName”: @“Palmorez”,
@“memberID”: @“12345”,
@“description”: @“This student is studying in…“,
@“fees”: @“100“,
@“deviceuser”: @“Platform1”,
@"created_on”: [CBLJSON JSONObjectWithDate: [NSDate date]]};

// Save the document:
CBLDocument* doc = [database createDocument];
NSError* error;

if (![doc putProperties: document error: &error]) {

}

Hi
Is your first question “My question is, is this way we have to manually update the data from client app to server?” resolved based on the response from Jens? (You need to have push replication going )
You have a second question that’s unrelated to the first question so bit confused here. To clarify, Couchbase Lite stores data as JSON documents . It is a document store.

I’ll create new question, i thought both questions are related to storing document.