Couchbase Design document not getting properly created in Couchbase 6.6 using JAVA SDK 2.7.13

When inserting a design document to a Couchbase bucket on Couchbase 6.6 using java sdk 2.7.13, the design document is not properly shown on couch UI.


Whereas a design document created from UI is shown properly

As shown in the image design document created for bucket test1 is created through UI and for bucket test2 is created using java sdk 2.7.13

Code used:
` Bucket bucket1 = cluster.openBucket(“test1”);
Bucket bucket2 = cluster.openBucket(“test2”);

List<View> viewsForCurrentDesignDocument = new ArrayList<>();
DesignDocument designDocument = DesignDocument.create(
    "my_design_doc",
    viewsForCurrentDesignDocument);

String mapFunction =
    "function (doc, meta) {\n" +
    "  emit(meta.id, doc);\n" +
    "}";

String reduceFunction = null;

View v = DefaultView.create("my_view1", mapFunction, reduceFunction);
viewsForCurrentDesignDocument.add(v);
//Creating a dev design document in bucket test2
bucket2.bucketManager().insertDesignDocument(designDocument, true);

//Getting dev design documents from bukects test1 and test2
System.out.println("Dev Desgin document in bucket test1" + bucket1.
    bucketManager().
    getDesignDocuments(true).toString());
System.out.println("Dev Design document in bucket test2" + bucket1.
    bucketManager().
    getDesignDocuments(true).toString());`

The output for getting the design document looks the same:

Dev Desgin document in bucket test1[DesignDocument{name=‘my_design_doc’, views=[DefaultView{name=‘my_view1’, map=‘function (doc, meta) {
emit(meta.id, null);
}’, reduce=‘null’}], options={}}]
Dev Design document in bucket test2[DesignDocument{name=‘my_design_doc’, views=[DefaultView{name=‘my_view1’, map=‘function (doc, meta) {
emit(meta.id, null);
}’, reduce=‘null’}], options={}}]

This issue doesn’t occur with other Couchbase versions such as 4.0 or 6.5.1
Also the same problems occurs for production views as well.
What can the causing this?

Hi @Kedar_Khedekar welcome to the forums.

Now that’s a bit weird @deniswsrosa can you help ?

Can you have a look at the logs, the couchdb log in particular, to see if there is a difference on 6.6 versus 6.5.1 when loading the view? Since it works with the older version of server and does not with the newer version of the server, it could be something that changed in 6.6. The best way to see/rule that out would be from the logs at the cluster side.

Also, does the insertDesignDocument() call return a DesignDocument successfully? Are any exceptions thrown? Per the docs, if the server response isn’t what is expected, an exception would be thrown.

Assuming a response does come back, you may want to look at it in the debugger or print it out.

I’ll also ask someone else to have a look and post here too.

If this is a test environment, it may also be great to get a packet capture of port 8092 for the creation against the two since you have the test environment. If you can supply that, or have a look at it first for the request/response and any differences, that’d be great.

@Kedar_Khedekar there is a small bug in your code - where you dump the output at the end in both cases you do it from bucket 1 (which is the one that does not exist). If you set that to bucket2 it should show it.

So I took your code, reduced it to one bucket and used it like this against 6.6

  public static void main(String... args) throws Exception {
    Cluster cluster = CouchbaseCluster.create("127.0.0.1");
    cluster.authenticate("Administrator", "password");
    Bucket bucket2 = cluster.openBucket("default");

    List<View> viewsForCurrentDesignDocument = new ArrayList<>();
    DesignDocument designDocument = DesignDocument.create(
      "my_design_doc",
      viewsForCurrentDesignDocument);

    String mapFunction =
      "function (doc, meta) {\n" +
        "  emit(meta.id, doc);\n" +
        "}";

    String reduceFunction = null;

    View v = DefaultView.create("my_view1", mapFunction, reduceFunction);
    viewsForCurrentDesignDocument.add(v);
    bucket2.bucketManager().insertDesignDocument(designDocument, true);


    System.out.println("Dev Design document in bucket test2" + bucket2.
      bucketManager().
      getDesignDocuments(true).toString());
  }

The output in the console:

Dev Design document in bucket test2[DesignDocument{name='my_design_doc2', views=[DefaultView{name='my_view1', map='function (doc, meta) {
  emit(meta.id, doc);
}', reduce='null'}], options={}}]

During trying this out though I noticed an issue that the UI did not properly delete my design docs (https://issues.couchbase.com/browse/MB-43179), maybe this could be related?

Try fixing the bucket1 vs bucket2 in the output and check if the server stored it properly and maybe it’s just the UI which has issues.

Updated code:
Bucket bucket1 = cluster.openBucket(“test1”);
Bucket bucket2 = cluster.openBucket(“test2”);

List<View> viewsForCurrentDesignDocument = new ArrayList<>();
DesignDocument designDocument = DesignDocument.create(
    "my_design_doc",
    viewsForCurrentDesignDocument);

String mapFunction =
    "function (doc, meta) {\n" +
    "  emit(meta.id, null);\n" +
    "}";

String reduceFunction = null;

View v = DefaultView.create("my_view1", mapFunction, reduceFunction);
viewsForCurrentDesignDocument.add(v);
//Creating a dev design document in bucket test2
bucket2.bucketManager().insertDesignDocument(designDocument, true);

//Getting dev design documents from bukects test1 and test2
System.out.println("Dev Desgin document in bucket test1" + bucket1.
    bucketManager().
    getDesignDocuments(true).toString());
System.out.println("Dev Design document in bucket test2" + bucket2.
    bucketManager().
    getDesignDocuments(true).toString());

Still the output is the same:

Dev Desgin document in bucket test1[DesignDocument{name=‘my_design_doc’, views=[DefaultView{name=‘my_view1’, map=‘function (doc, meta) {
emit(meta.id, null);
}’, reduce=‘null’}], options={}}]
Dev Design document in bucket test2[DesignDocument{name=‘my_design_doc’, views=[DefaultView{name=‘my_view1’, map=‘function (doc, meta) {
emit(meta.id, null);
}’, reduce=‘null’}], options={}}]

@daschl As shown in the image in the first post , the view created through SDK is having the issue whereas the one created through UI looks fine. The getDesignDocument is returning the same result for both the views, the one created through UI as well as for view created through SDK, so I think maybe the issue is related to UI as you mentioned for delete

I guess the question @Kedar_Khedekar is does the view work properly when 2.7.13 creates it against 6.6? If so, then it’s simply a UI bug. For what it’s worth, we do have test coverage for this functionally in SDKs. There could always be a case we don’t have covered, but it could also just be a UI bug as most of the observations seem to be leading to.

@daschl @ingenthr, I can see the UI issue jira which was created for this https://issues.couchbase.com/browse/MB-43179 being fixed. Is there a couchbase server edition which i can use which has this fix?

@Kedar_Khedekar from the ticket it looks like this is going to be in 6.6.2 and 7.0