Savings issue with JSON


I am developing iOS application using Couchbase Lite and Grocery sample app. I have the following queries, could someone help with answers please?

  1. The sample uses JSON like below,

NSDictionary *document = @{@“text”: text,
@“check”: @NO,
@“created_at”: [CBLJSON JSONObjectWithDate: [NSDate date]]};

The above JSON format has been synced data to server without any issues.

If i change to,

NSDictionary *document = @{@“Item”: text,
@“Enable”: @NO,
@“Name”: @“Myname”,
@“Created_at”: [CBLJSON JSONObjectWithDate: [NSDate date]]};

This data has not been synced to server, it does nothing. Can’t I add/change JSON key-value as per my own? Is there any specific mandated items i should have them in JSON?

  1. Is there any maximum size limit to store document in Couchbase lite on the mobile (iOS and android)? How many records/documents i can totally store in the mobile app?

You should be able to change the JSON doc and it should sync up. Note that if you changed the JSON keys (including the case), you will have to update the app to refer to the right keys in other places in the app as well.
For instance, the code snippet where view is created, you will have to updated “created_by” to “Created_by”. Similarly, in the rest of the app…

 [[theDatabase viewNamed: @"byDate"] setMapBlock: MAPBLOCK({
        id date = doc[@"Created_at"];
        if (date)
            emit(date, doc);
    }) reduceBlock: nil version: @"1.1"];

Hi Priya,

I do have this code as below.

  • (void)useDatabase:(CBLDatabase*)theDatabase {
    database = theDatabase;
// Define a view with a map function that indexes to-do items by creation date:
[[theDatabase viewNamed: @"byDate"] setMapBlock: MAPBLOCK({
    id date = doc[@"created_at"];
    if (date)
        emit(date, doc);
}) reduceBlock: nil version: @"1.1"];

// and a validation function requiring parseable dates:
[theDatabase setValidationNamed: @"created_at" asBlock: VALIDATIONBLOCK({
    if (newRevision.isDeletion)
    id date = ([@"created_at"];
    if (date && ! [CBLJSON dateWithJSONObject: date]) {
        [context rejectWithMessage: [@"invalid date " stringByAppendingString: [date description]]];


but i can’t change JSON document as I mentioned earlier.

I am going to assume that you didn’t get any error when you made the createDocument() call.

  1. Your document has “Created_at” as the key (with capital C) but the snippet is “created_at”- Keys are case sensitive. Or is the formatting lost in the copy and paste ?

  2. Also, as suggested earlier, did you change other references to the document in the app.
    For instance, you updated “text” to “Item”, did you change the corresponding code -
    - (void) viewDidLoad {

      dataSource.labelProperty = @"Text"; // CHANGE THIS TO THE NEW KEY

Do this for all the keys you changed in your new document


How do you know the document wasn’t synced to the server?

Couchbase Lite doesn’t have any size limits on documents, but Couchbase Server has a limit of 20MB (encoded as JSON.) In practice, it’s probably a bad idea to shove that much data into a single document, since it will be quite slow to parse and replicate.

Excellent Priya. I’ll try that.