0

I am developing a react-native application and I am using Couchbase lite as a database locally. The way this works is that you spawn a local REST server when the app starts and you use the REST API to communicate with the CouchbaseLite server.

I have created a few design documents, but when I try to update those I do not get the new results when I run my REST client (seperate app I use for debugging). When I GET the design document it has a new _rev after the update, the new map function is as I updated it, but whenever I do a get on the view the result is the same as the first version of the map function.

Apparently the updated docs are not used by get.

The design doc:

var designDoc = {
  name: 'expenses',
  language: 'javascript',
  views: {
    contact_parts_for_group: {
      'map': function(doc){
        if(doc.type == 'expense'){
          emit('some things I emit', doc.amount)
        }
      }.toString()
    }
  }
};

I send this to the server along with the proper _rev as the json body: JSON.stringify(designDoc) .1. I am updating my design document with a PUT call:

PUT /kittydb/_design/expenses?rev=4-6f89f1e13d1fbb89c712d6bab53ee7d4 HTTP/1.1
Host: 127.0.0.1:5800
Connection: close
User-Agent: Paw/2.2.2 (Macintosh; OS X/10.11.2) GCDHTTPRequest
Content-Length: 356

{"name":"expenses","language":"javascript","views":{"contact_parts_for_group":{"map":"function (doc){ if(doc.type=='expense'){ var i,len,part,ref;  ref=doc.parts; for(i=0,len=ref.length;i<len;i++){ part=ref[i]; var amount=part.contact==doc.expense_by?-1*part.amount:part.amount; emit([doc.group_id,part.contact,part.contact==doc.expense_by],amount);}}}"}}}

.2. I populate the database using the interface of the app prototype I developed so far

.3. I am not sure what you mean by this.

.4. This is the get:

GET /kittydb/_design/expenses/_view/contact_parts_for_group HTTP/1.1
Host: 127.0.0.1:5800
Connection: close
User-Agent: Paw/2.2.2 (Macintosh; OS X/10.11.2) GCDHTTPRequest

More information in reaction to some comments:

I am using the CouchbaseLite Community Edition, version 1.1.1 for iOS. I am running the simulator as an iPhone 6 with iOS 9.2.

I made some screenshots to illustrate what is going on a bit more:

first result

I don't know how to retrieve the map function that goes with this but what it seems to do is:

emit([doc.group_id,part.contact],amount)

I used the get as above.

Now my update:

PUT /kittydb/_design/expenses?rev=7-6f979706f38acce9c7db380fba8565e4 HTTP/1.1
Host: 127.0.0.1:5800
Connection: close
User-Agent: Paw/2.2.2 (Macintosh; OS X/10.11.2) GCDHTTPRequest
Content-Length: 350

{
  "name": "expenses",
  "language": "javascript",
  "views": {
    "contact_parts_for_group": {
      "map": "function (doc){ if(doc.type=='expense'){ var i,len,part,ref;  ref=doc.parts; for(i=0,len=ref.length;i<len;i++){ part=ref[i]; var amount=part.contact==doc.expense_by?-1*part.amount:part.amount; emit('Hello SO', 'Overflow');}}}"
    }
  }
}

What it should do now is: emit('Hello SO', 'Overflow');

I get this response when I run the above request:

HTTP/1.1 201 Created
Location: http://127.0.0.1:5800/kittydb/_design/expenses
Content-Type: application/json
Server: CouchbaseLite 1.1 (unofficial)
Etag: "8-3ae4b6ff37b936657ca23acb8d836619"
Accept-Ranges: bytes
Date: Wed, 20 Jan 2016 21:57:03 GMT
Transfer-Encoding: chunked

{"id":"_design\/expenses","rev":"8-3ae4b6ff37b936657ca23acb8d836619","ok":true}

Now I run the get request again:

nothing changed

And nothing changed...

When I create a new document with 'type = expense' I get the same result, just more of them.

Mosselman
  • 1,718
  • 15
  • 27
  • Hey @Mosselman, couple of questions and comments regarding the above: [1] How are you updating your documents? eg. PUT calls or directly modifying the database? [2] When you start with a blank empty document, how are the new results populated on the client side? [3] Your map function should not be or have changed after updating documents as the map function checks whether the document type represents an 'expense'. And if it does, it calls emit to add 'X' and 'amount' to the index which from there can query to look up something or someone. [4] Can you share your GET query? – sweetiewill Jan 20 '16 at 03:14
  • @sweetiewill thanks for having a look. Could it be indexing? How can I clear the index for this view? Also, I added answers to your questions above. – Mosselman Jan 20 '16 at 14:58
  • What version and platform of Couchbase Lite? (I.e. 1.1 for iOS, 1.1.1 for .NET/Xamarin, etc.) – Jens Alfke Jan 20 '16 at 18:40
  • You seem to be doing everything correctly so I can't think of why you'd get stale results. You're checking the response status of each request and not seeing any errors? – Jens Alfke Jan 20 '16 at 18:42
  • @JensAlfke thanks for having a look. I updated my question with more info. I checked everything step by step as you can see, but still no dice. – Mosselman Jan 20 '16 at 22:00

1 Answers1

0

I don't know how to retrieve the map function that goes with this

Aha -- if you don't know where the original view definition is, and you can't get it from the design document, it's probably being defined in native code (at app launch time.) Such a definition will override one in a design document.

I don't know anything about React-Native. Is there (as the name implies) native code in the app? If so, look for a call to [CBLView setMapBlock: ...].

Jens Alfke
  • 1,946
  • 12
  • 15
  • Thank you @jens-alfke, but that is not the case. My views are created through my own REST calls to the CouchBaseLite server running on the phone. I meant that I cannot retrieve the `_rev: 1......` version of the design document as I don't know its revision id. – Mosselman Jan 22 '16 at 13:31