Class Databases

java.lang.Object
org.restheart.mongodb.db.Databases

public class Databases extends Object
Author:
Andrea Di Cesare <andrea@softinstigate.com>
  • Field Details

    • PROPS_QUERY

      public static final org.bson.conversions.Bson PROPS_QUERY
  • Method Details

    • get

      public static Databases get()
    • doesDbExist

      public boolean doesDbExist(Optional<com.mongodb.client.ClientSession> cs, Optional<RSOps> rsOps, String dbName)
      Returns true if the collection exists
      Parameters:
      cs - the client session
      rsOps - the ReplicaSet connection options
      dbName - the name of the db
      Returns:
      true if the db exists
    • getCollectionNames

      public List<String> getCollectionNames(Optional<com.mongodb.client.ClientSession> cs, Optional<RSOps> rsOps, String dbName)
      Parameters:
      cs - the client session
      rsOps - the ReplicaSet connection options
      dbName - the database name
      Returns:
      A ordered List of collection names
    • getDBSize

      public long getDBSize(List<String> colls)
      Parameters:
      colls - the collections list got from getCollectionNames()
      Returns:
      the number of collections in this db
    • getDatabaseProperties

      public org.bson.BsonDocument getDatabaseProperties(Optional<com.mongodb.client.ClientSession> cs, Optional<RSOps> rsOps, String dbName)
      Parameters:
      cs - the client session
      rsOps - the ReplicaSet connection options
      dbName - the database name
      Returns:
      the db props
    • getDatabaseData

      public org.bson.BsonArray getDatabaseData(Optional<com.mongodb.client.ClientSession> cs, Optional<RSOps> rsOps, String dbName, List<String> colls, int page, int pagesize, boolean noCache) throws IllegalQueryParamenterException
      Parameters:
      cs - the client session
      rsOps - the ReplicaSet connection options
      dbName - the database name
      colls - the collections list as got from getCollectionNames()
      page -
      pagesize -
      noCache -
      Returns:
      the db data
      Throws:
      IllegalQueryParamenterException
    • upsertDB

      public OperationResult upsertDB(Optional<com.mongodb.client.ClientSession> cs, Optional<RSOps> rsOps, String dbName, ExchangeKeys.METHOD method, boolean updating, org.bson.BsonDocument newContent, String requestEtag, boolean checkEtag)
      Parameters:
      cs - the client session
      rsOps - the ReplicaSet connection options
      dbName - the database name
      method -
      updating -
      newContent -
      requestEtag -
      Returns:
      the OperationResult
    • deleteDatabase

      public OperationResult deleteDatabase(Optional<com.mongodb.client.ClientSession> cs, Optional<RSOps> rsOps, String dbName, org.bson.BsonObjectId requestEtag, boolean checkEtag)
      Parameters:
      cs - the client session
      rsOps - the ReplicaSet connection options
      dbName - the database name
      requestEtag -
      checkEtag -
      Returns:
      the OperationResult
    • getDatabaseNames

      public List<String> getDatabaseNames(Optional<com.mongodb.client.ClientSession> cs)
      Parameters:
      cs - the client session
      Returns:
      and ordered list of the databases
    • getCollectionProperties

      public org.bson.BsonDocument getCollectionProperties(Optional<com.mongodb.client.ClientSession> cs, Optional<RSOps> rsOps, String dbName, String collName)
      Parameters:
      cs - the client session
      rsOps - the ReplicaSet connection options
      dbName - the database name
      collName -
      Returns:
      the collection properties
    • collection

      public com.mongodb.client.MongoCollection<org.bson.BsonDocument> collection(Optional<RSOps> rsOps, String dbName, String collName)
      Parameters:
      rsOps - the ReplicaSet connection options
      dbName - the database name
      collName -
      Returns:
      the MongoCollection
    • getCollectionSize

      public long getCollectionSize(Optional<com.mongodb.client.ClientSession> cs, Optional<RSOps> rsOps, String dbName, String collName, org.bson.BsonDocument filter)
      Returns the number of documents in the given collection (taking into account the filters in case).
      Parameters:
      cs - the ClientSession
      rsOps - the ReplicaSet connection options
      dbName - the database name
      collName - the collection name
      filters - the filters to apply. it is a Deque collection of mongodb query conditions.
      Returns:
      the number of documents in the given collection (taking into account the filters in case)
    • getCollectionData

      public org.bson.BsonArray getCollectionData(Optional<com.mongodb.client.ClientSession> cs, Optional<RSOps> rsOps, String dbName, String collName, int page, int pagesize, org.bson.BsonDocument sortBy, org.bson.BsonDocument filters, org.bson.BsonDocument hint, org.bson.BsonDocument keys, boolean useCache) throws org.bson.json.JsonParseException
      Parameters:
      cs - the client session
      rsOps - the ReplicaSet connection options
      dbName - the database name
      collName - the collection name
      page -
      pagesize -
      sortBy -
      filter -
      hint -
      keys -
      useCache -
      Returns:
      the documents in the collection as a BsonArray
      Throws:
      org.bson.json.JsonParseException
    • deleteCollection

      public OperationResult deleteCollection(Optional<com.mongodb.client.ClientSession> cs, Optional<RSOps> rsOps, String dbName, String collName, org.bson.BsonObjectId requestEtag, boolean checkEtag)
      Parameters:
      cs - the client session
      rsOps - the ReplicaSet connection options
      dbName - the database name
      collName - the collection name
      requestEtag -
      checkEtag -
      Returns:
      the OperationResult
    • upsertCollection

      public OperationResult upsertCollection(Optional<com.mongodb.client.ClientSession> cs, Optional<RSOps> rsOps, String dbName, String collName, ExchangeKeys.METHOD method, boolean updating, org.bson.BsonDocument content, String requestEtag, boolean checkEtag)
      Parameters:
      cs - the client session
      rsOps - the ReplicaSet connection options
      dbName - the database name
      method - the request method
      updating - true if updating, false if creating
      collName -
      content -
      requestEtag -
      checkEtag -
      Returns:
      the OperationResult
    • deleteIndex

      public int deleteIndex(Optional<com.mongodb.client.ClientSession> cs, Optional<RSOps> rsOps, String dbName, String collection, String indexId)
      Parameters:
      cs - the client session
      rsOps - the ReplicaSet connection options
      dbName - the database name
      collection -
      indexId -
      Returns:
      the HTTP status code
    • getCollectionIndexes

      public List<org.bson.BsonDocument> getCollectionIndexes(Optional<com.mongodb.client.ClientSession> cs, Optional<RSOps> rsOps, String dbName, String collectionName)
      Parameters:
      cs - the client session
      rsOps - the ReplicaSet connection options
      dbName - the database name
      collectionName -
      Returns:
      an ordered list of the indexes
    • findIterable

      public com.mongodb.client.FindIterable<org.bson.BsonDocument> findIterable(Optional<com.mongodb.client.ClientSession> cs, Optional<RSOps> rsOps, String dbName, String collName, org.bson.BsonDocument sortBy, org.bson.BsonDocument filters, org.bson.BsonDocument hint, org.bson.BsonDocument keys, int batchSize)
      Parameters:
      cs - the client session
      rsOps - the ReplicaSet connection options
      dbName - the database name
      collName - the collection name
      sortBy -
      filters -
      hint -
      keys -
      batchSize -
      Returns:
      the FindIterable
    • createIndex

      public void createIndex(Optional<com.mongodb.client.ClientSession> cs, Optional<RSOps> rsOps, String dbName, String collName, org.bson.BsonDocument keys, Optional<org.bson.BsonDocument> options)
      Parameters:
      cs - the client session
      rsOps - the ReplicaSet connection options
      dbName - the database name
      collName - the collection name
      keys -
      options -