_class property in CouchBase










0















I have a document stored in Couchbase.




"a":
"b":
"key":"Value"
,
"_class":"com.nikhil.model"
,
"c":
"d":
"key":"value"
,
// _class is missing here
,
"_class": "com.nikhil.model"



Here as you can see I don't have an _class inside the "d" in the doucument because of this I am not able to get this document. An object mapping exception came.
_class is used to map the nested object of couchbase to the model required for mapping but inside the "c" object I don't have this _Class property that is why a mapping exception comes.
Is there any fix for this?










share|improve this question
























  • This json isn't valid (even when removing the comment), you may want to update it for accuracy (check out jsonlint.com if you need help)

    – Matthew Groves
    Nov 15 '18 at 14:57















0















I have a document stored in Couchbase.




"a":
"b":
"key":"Value"
,
"_class":"com.nikhil.model"
,
"c":
"d":
"key":"value"
,
// _class is missing here
,
"_class": "com.nikhil.model"



Here as you can see I don't have an _class inside the "d" in the doucument because of this I am not able to get this document. An object mapping exception came.
_class is used to map the nested object of couchbase to the model required for mapping but inside the "c" object I don't have this _Class property that is why a mapping exception comes.
Is there any fix for this?










share|improve this question
























  • This json isn't valid (even when removing the comment), you may want to update it for accuracy (check out jsonlint.com if you need help)

    – Matthew Groves
    Nov 15 '18 at 14:57













0












0








0








I have a document stored in Couchbase.




"a":
"b":
"key":"Value"
,
"_class":"com.nikhil.model"
,
"c":
"d":
"key":"value"
,
// _class is missing here
,
"_class": "com.nikhil.model"



Here as you can see I don't have an _class inside the "d" in the doucument because of this I am not able to get this document. An object mapping exception came.
_class is used to map the nested object of couchbase to the model required for mapping but inside the "c" object I don't have this _Class property that is why a mapping exception comes.
Is there any fix for this?










share|improve this question
















I have a document stored in Couchbase.




"a":
"b":
"key":"Value"
,
"_class":"com.nikhil.model"
,
"c":
"d":
"key":"value"
,
// _class is missing here
,
"_class": "com.nikhil.model"



Here as you can see I don't have an _class inside the "d" in the doucument because of this I am not able to get this document. An object mapping exception came.
_class is used to map the nested object of couchbase to the model required for mapping but inside the "c" object I don't have this _Class property that is why a mapping exception comes.
Is there any fix for this?







couchbase spring-data-couchbase






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 14:26









Matthew Groves

16.3k855104




16.3k855104










asked Nov 15 '18 at 5:49









NikhilNikhil

18312




18312












  • This json isn't valid (even when removing the comment), you may want to update it for accuracy (check out jsonlint.com if you need help)

    – Matthew Groves
    Nov 15 '18 at 14:57

















  • This json isn't valid (even when removing the comment), you may want to update it for accuracy (check out jsonlint.com if you need help)

    – Matthew Groves
    Nov 15 '18 at 14:57
















This json isn't valid (even when removing the comment), you may want to update it for accuracy (check out jsonlint.com if you need help)

– Matthew Groves
Nov 15 '18 at 14:57





This json isn't valid (even when removing the comment), you may want to update it for accuracy (check out jsonlint.com if you need help)

– Matthew Groves
Nov 15 '18 at 14:57












3 Answers
3






active

oldest

votes


















2














If you are using Spring boot, you need to override the typekey() method in the Couchbase Config file which extends AbstractCouchbaseConfiguration and return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE. This will replace your _class with javaClass string in the documents stored in Couchbase Server. I hope this helps.



@Configuration
public class RemoteCouchbaseConfiguration extends AbstractCouchbaseConfiguration

@Value("$couchbase.host")
private String host;

@Value("$couchbase.bucket.bucketName")
private String bucketName;

@Value("$couchbase.bucket.password")
private String password;

@Override
protected List<String> getBootstrapHosts()
return Arrays.asList(this.host);


@Override
protected String getBucketName()
return this.bucketName;


@Override
protected String getBucketPassword()
return this.password;


@Override
public String typeKey()
return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE;







share|improve this answer






























    1














    Looks like you are using Couchbase with Spring Data, the easiest way is to return a projection:



    @Override
    public List<UserVO> getUsers(String companyId, List<String> userIds)

    String queryString = "SELECT meta(t).id as id, t.login as login, t.firstName as firstName from " + getBucketName() + " t where t."+getClassFilter()+" "
    + " and t.companyId = '" + companyId + "' and t.isEnabled = true and t.isVisible = true "
    + " and meta(t).id in ["+userIds.stream().map(e->"'"+e+"'").collect( Collectors.joining( "," )) +"]";
    N1qlParams params = N1qlParams.build().consistency(ScanConsistency.NOT_BOUNDED).adhoc(true);
    ParameterizedN1qlQuery query = N1qlQuery.parameterized(queryString, JsonObject.create(), params);

    return userRepository.getCouchbaseOperations().findByN1QLProjection(query, UserVO.class);






    share|improve this answer


















    • 1





      Cannot we do this using Spring repository like using JPA ?

      – Nikhil
      Nov 16 '18 at 5:40






    • 1





      No, but there is already a ticket requesting this feature.

      – deniswsrosa
      Nov 16 '18 at 9:51


















    0














    You could add _class to it using an UPDATE N1QL statement like this:



    UPDATE mybucket b
    SET b.c.d._class = 'com.foo.bar'
    WHERE b.c.d IS NOT MISSING
    AND b.c.d._class IS MISSING


    That will update any document that has a 'd' object within a 'c' object but doesn't have a '_class' within the c object.






    share|improve this answer






















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313187%2fclass-property-in-couchbase%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      If you are using Spring boot, you need to override the typekey() method in the Couchbase Config file which extends AbstractCouchbaseConfiguration and return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE. This will replace your _class with javaClass string in the documents stored in Couchbase Server. I hope this helps.



      @Configuration
      public class RemoteCouchbaseConfiguration extends AbstractCouchbaseConfiguration

      @Value("$couchbase.host")
      private String host;

      @Value("$couchbase.bucket.bucketName")
      private String bucketName;

      @Value("$couchbase.bucket.password")
      private String password;

      @Override
      protected List<String> getBootstrapHosts()
      return Arrays.asList(this.host);


      @Override
      protected String getBucketName()
      return this.bucketName;


      @Override
      protected String getBucketPassword()
      return this.password;


      @Override
      public String typeKey()
      return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE;







      share|improve this answer



























        2














        If you are using Spring boot, you need to override the typekey() method in the Couchbase Config file which extends AbstractCouchbaseConfiguration and return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE. This will replace your _class with javaClass string in the documents stored in Couchbase Server. I hope this helps.



        @Configuration
        public class RemoteCouchbaseConfiguration extends AbstractCouchbaseConfiguration

        @Value("$couchbase.host")
        private String host;

        @Value("$couchbase.bucket.bucketName")
        private String bucketName;

        @Value("$couchbase.bucket.password")
        private String password;

        @Override
        protected List<String> getBootstrapHosts()
        return Arrays.asList(this.host);


        @Override
        protected String getBucketName()
        return this.bucketName;


        @Override
        protected String getBucketPassword()
        return this.password;


        @Override
        public String typeKey()
        return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE;







        share|improve this answer

























          2












          2








          2







          If you are using Spring boot, you need to override the typekey() method in the Couchbase Config file which extends AbstractCouchbaseConfiguration and return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE. This will replace your _class with javaClass string in the documents stored in Couchbase Server. I hope this helps.



          @Configuration
          public class RemoteCouchbaseConfiguration extends AbstractCouchbaseConfiguration

          @Value("$couchbase.host")
          private String host;

          @Value("$couchbase.bucket.bucketName")
          private String bucketName;

          @Value("$couchbase.bucket.password")
          private String password;

          @Override
          protected List<String> getBootstrapHosts()
          return Arrays.asList(this.host);


          @Override
          protected String getBucketName()
          return this.bucketName;


          @Override
          protected String getBucketPassword()
          return this.password;


          @Override
          public String typeKey()
          return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE;







          share|improve this answer













          If you are using Spring boot, you need to override the typekey() method in the Couchbase Config file which extends AbstractCouchbaseConfiguration and return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE. This will replace your _class with javaClass string in the documents stored in Couchbase Server. I hope this helps.



          @Configuration
          public class RemoteCouchbaseConfiguration extends AbstractCouchbaseConfiguration

          @Value("$couchbase.host")
          private String host;

          @Value("$couchbase.bucket.bucketName")
          private String bucketName;

          @Value("$couchbase.bucket.password")
          private String password;

          @Override
          protected List<String> getBootstrapHosts()
          return Arrays.asList(this.host);


          @Override
          protected String getBucketName()
          return this.bucketName;


          @Override
          protected String getBucketPassword()
          return this.password;


          @Override
          public String typeKey()
          return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE;








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 15 at 21:53









          awasumawasum

          213




          213























              1














              Looks like you are using Couchbase with Spring Data, the easiest way is to return a projection:



              @Override
              public List<UserVO> getUsers(String companyId, List<String> userIds)

              String queryString = "SELECT meta(t).id as id, t.login as login, t.firstName as firstName from " + getBucketName() + " t where t."+getClassFilter()+" "
              + " and t.companyId = '" + companyId + "' and t.isEnabled = true and t.isVisible = true "
              + " and meta(t).id in ["+userIds.stream().map(e->"'"+e+"'").collect( Collectors.joining( "," )) +"]";
              N1qlParams params = N1qlParams.build().consistency(ScanConsistency.NOT_BOUNDED).adhoc(true);
              ParameterizedN1qlQuery query = N1qlQuery.parameterized(queryString, JsonObject.create(), params);

              return userRepository.getCouchbaseOperations().findByN1QLProjection(query, UserVO.class);






              share|improve this answer


















              • 1





                Cannot we do this using Spring repository like using JPA ?

                – Nikhil
                Nov 16 '18 at 5:40






              • 1





                No, but there is already a ticket requesting this feature.

                – deniswsrosa
                Nov 16 '18 at 9:51















              1














              Looks like you are using Couchbase with Spring Data, the easiest way is to return a projection:



              @Override
              public List<UserVO> getUsers(String companyId, List<String> userIds)

              String queryString = "SELECT meta(t).id as id, t.login as login, t.firstName as firstName from " + getBucketName() + " t where t."+getClassFilter()+" "
              + " and t.companyId = '" + companyId + "' and t.isEnabled = true and t.isVisible = true "
              + " and meta(t).id in ["+userIds.stream().map(e->"'"+e+"'").collect( Collectors.joining( "," )) +"]";
              N1qlParams params = N1qlParams.build().consistency(ScanConsistency.NOT_BOUNDED).adhoc(true);
              ParameterizedN1qlQuery query = N1qlQuery.parameterized(queryString, JsonObject.create(), params);

              return userRepository.getCouchbaseOperations().findByN1QLProjection(query, UserVO.class);






              share|improve this answer


















              • 1





                Cannot we do this using Spring repository like using JPA ?

                – Nikhil
                Nov 16 '18 at 5:40






              • 1





                No, but there is already a ticket requesting this feature.

                – deniswsrosa
                Nov 16 '18 at 9:51













              1












              1








              1







              Looks like you are using Couchbase with Spring Data, the easiest way is to return a projection:



              @Override
              public List<UserVO> getUsers(String companyId, List<String> userIds)

              String queryString = "SELECT meta(t).id as id, t.login as login, t.firstName as firstName from " + getBucketName() + " t where t."+getClassFilter()+" "
              + " and t.companyId = '" + companyId + "' and t.isEnabled = true and t.isVisible = true "
              + " and meta(t).id in ["+userIds.stream().map(e->"'"+e+"'").collect( Collectors.joining( "," )) +"]";
              N1qlParams params = N1qlParams.build().consistency(ScanConsistency.NOT_BOUNDED).adhoc(true);
              ParameterizedN1qlQuery query = N1qlQuery.parameterized(queryString, JsonObject.create(), params);

              return userRepository.getCouchbaseOperations().findByN1QLProjection(query, UserVO.class);






              share|improve this answer













              Looks like you are using Couchbase with Spring Data, the easiest way is to return a projection:



              @Override
              public List<UserVO> getUsers(String companyId, List<String> userIds)

              String queryString = "SELECT meta(t).id as id, t.login as login, t.firstName as firstName from " + getBucketName() + " t where t."+getClassFilter()+" "
              + " and t.companyId = '" + companyId + "' and t.isEnabled = true and t.isVisible = true "
              + " and meta(t).id in ["+userIds.stream().map(e->"'"+e+"'").collect( Collectors.joining( "," )) +"]";
              N1qlParams params = N1qlParams.build().consistency(ScanConsistency.NOT_BOUNDED).adhoc(true);
              ParameterizedN1qlQuery query = N1qlQuery.parameterized(queryString, JsonObject.create(), params);

              return userRepository.getCouchbaseOperations().findByN1QLProjection(query, UserVO.class);







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 15 '18 at 19:46









              deniswsrosadeniswsrosa

              559515




              559515







              • 1





                Cannot we do this using Spring repository like using JPA ?

                – Nikhil
                Nov 16 '18 at 5:40






              • 1





                No, but there is already a ticket requesting this feature.

                – deniswsrosa
                Nov 16 '18 at 9:51












              • 1





                Cannot we do this using Spring repository like using JPA ?

                – Nikhil
                Nov 16 '18 at 5:40






              • 1





                No, but there is already a ticket requesting this feature.

                – deniswsrosa
                Nov 16 '18 at 9:51







              1




              1





              Cannot we do this using Spring repository like using JPA ?

              – Nikhil
              Nov 16 '18 at 5:40





              Cannot we do this using Spring repository like using JPA ?

              – Nikhil
              Nov 16 '18 at 5:40




              1




              1





              No, but there is already a ticket requesting this feature.

              – deniswsrosa
              Nov 16 '18 at 9:51





              No, but there is already a ticket requesting this feature.

              – deniswsrosa
              Nov 16 '18 at 9:51











              0














              You could add _class to it using an UPDATE N1QL statement like this:



              UPDATE mybucket b
              SET b.c.d._class = 'com.foo.bar'
              WHERE b.c.d IS NOT MISSING
              AND b.c.d._class IS MISSING


              That will update any document that has a 'd' object within a 'c' object but doesn't have a '_class' within the c object.






              share|improve this answer



























                0














                You could add _class to it using an UPDATE N1QL statement like this:



                UPDATE mybucket b
                SET b.c.d._class = 'com.foo.bar'
                WHERE b.c.d IS NOT MISSING
                AND b.c.d._class IS MISSING


                That will update any document that has a 'd' object within a 'c' object but doesn't have a '_class' within the c object.






                share|improve this answer

























                  0












                  0








                  0







                  You could add _class to it using an UPDATE N1QL statement like this:



                  UPDATE mybucket b
                  SET b.c.d._class = 'com.foo.bar'
                  WHERE b.c.d IS NOT MISSING
                  AND b.c.d._class IS MISSING


                  That will update any document that has a 'd' object within a 'c' object but doesn't have a '_class' within the c object.






                  share|improve this answer













                  You could add _class to it using an UPDATE N1QL statement like this:



                  UPDATE mybucket b
                  SET b.c.d._class = 'com.foo.bar'
                  WHERE b.c.d IS NOT MISSING
                  AND b.c.d._class IS MISSING


                  That will update any document that has a 'd' object within a 'c' object but doesn't have a '_class' within the c object.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 15 '18 at 14:59









                  Matthew GrovesMatthew Groves

                  16.3k855104




                  16.3k855104



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313187%2fclass-property-in-couchbase%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      How to read a connectionString WITH PROVIDER in .NET Core?

                      Node.js Script on GitHub Pages or Amazon S3

                      Museum of Modern and Contemporary Art of Trento and Rovereto