Monday 27 September 2021

ArangoDB: Drop a collection Using Java driver

 ArangoCollection interface provides 'drop' method to drop a collection.

 

void drop() throws ArangoDBException;

Drop a collection.

 

void drop(boolean isSystem) throws ArangoDBException;

'isSystem' must be set to true to drop a system collection.

 

Find the below working application.

 

CollectionDropDemo.java

package com.sample.app;

import com.arangodb.ArangoCollection;
import com.arangodb.ArangoDB;
import com.arangodb.ArangoDatabase;
import com.arangodb.mapping.ArangoJack;

public class CollectionDropDemo {
    private static final String USER_NAME = "root";
    private static final String PASSWORD = "tiger";
    private static final String HOST = "127.0.0.1";
    private static final int PORT = 8529;

    public static void main(String args[]) {
        // Get an ArangoDB instance
        ArangoDB arangoDB = new ArangoDB.Builder().user(USER_NAME).password(PASSWORD).host(HOST, PORT)
                .serializer(new ArangoJack()).build();

        String databaseName = "testdb";
        arangoDB.createDatabase(databaseName);

        ArangoDatabase arangoDatabase = arangoDB.db(databaseName);

        String collectionName = "users";

        arangoDatabase.createCollection(collectionName);

        ArangoCollection arangoCollection = arangoDatabase.collection(collectionName);

        // Dropping the collection and database
        arangoCollection.drop();
        arangoDatabase.drop();
    }
}

 

 

  

Previous                                                    Next                                                    Home

No comments:

Post a Comment