How to Create and Delete a Scope Using Couchbase Lite Java SDK

I have been trying to create and delete a scope using the Couchbase Lite Java SDK, but I’m struggling to find relevant information in the documentation and source code. I’ve scoured through the available resources, but there seems to be a lack of clear guidance on how to achieve this essential task. I would greatly appreciate any assistance and clarification regarding this matter.

Problem Statement:

  1. Creating a Scope: I need to understand how to create a scope programmatically using the Couchbase Lite Java SDK. I couldn’t find any clear examples or documentation explaining the steps and methods required to achieve this.
  2. Deleting a Scope: Similarly, I need guidance on how to delete a scope that is no longer needed. The process for safely deleting a scope while ensuring data integrity is something I’m struggling to comprehend.

Request: I kindly request the Couchbase Lite community and the development team to provide clear and detailed instructions, code examples, or references to relevant documentation that explain how to create and delete a scope using the Couchbase Lite Java SDK. This information would be invaluable for developers who are working with Couchbase Lite and are looking to manage their data effectively.

Your assistance in addressing this issue would be greatly appreciated, and it will help improve the overall usability and understanding of Couchbase Lite’s functionality.

Thank you for your time and support.

Hi @teetangh ,

A scope will be created when its first collection is created. Thus, you can use createCollection(“collectionA”, “newScope”) to create a new collection in a new scope.
Respectively, a scope will be automatically deleted when its last collection its been deleted - in other words, you can’t have empty scopes.

Vlad has it right… but let me add an explanation that may help.

Scopes don’t actually exist.

Scopes are just namespaces. If there are collections in a given scope, that scope exists. If there are no collections in a scope, then it doesn’t exist.

There is really nothing to create or delete: scopes are entirely ephemeral.