Class MongoDatabase
java.lang.Object
dev.magicmq.pyspigot.manager.database.Database
dev.magicmq.pyspigot.manager.database.mongo.MongoDatabase
Represents an open connection to a Mongo Database.
 
Note: Most methods in this class should be called from scripts only!
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionbooleanclose()Closes a connection to the database.booleancreateCollection(String database, String collection) Create a collection in the given databasecreateCollectionIndex(String database, String collection, Bson keys) Create a collection with an index of the given keys.Create an emptyDocument.createDocument(String json) Create aDocumentout of the provided json.createDocument(String key, Object value) Create aDocumentwith the provided key and value.Create a new emptyBasicDBObject.createObject(String json) Create a newBasicDBObjectout of the provided json.createObject(String key, Object value) Create a newBasicDBObjectwith the provided key and value.booleandeleteCollection(String database, String collection) Delete a collection in the given databasedeleteDocument(String database, String collection, Bson filter) Delete a document from a collection matching the provided filter.deleteDocuments(String database, String collection, Bson filter) Delete multiple documents from a collection matching the provided filter.booleandoesCollectionExist(String database, String collection) Check if a collection exists within a database.booleandoesDatabaseExist(String database) Check if a database exists with the given name.Fetch a newFindOneAndUpdateOptionsobject for updatesFetch a newUpdateOptionsobject for updatesUpdate and return a document within a collection that match the given filter, with the default update optionsfindAndUpdateDocument(String database, String collection, Bson filter, List<Bson> update, FindOneAndUpdateOptions updateOptions) Update and return a document within a collection that match the given filter, with the default update optionsfindAndUpdateDocument(String database, String collection, Bson filter, Bson update) Update and return a document within a collection that match the given filter, with the default update optionsfindAndUpdateDocument(String database, String collection, Bson filter, Bson update, FindOneAndUpdateOptions updateOptions) Update and return a document within a collection that match the given filter, with the default update optionsgetCollection(String database, String collection) Get a collection from a database.getCollectionNames(String database) Get all collection names within a database.getCollections(String database) Get all collections within a database.getDatabase(String database) Get aMongoDatabasewith the given name.Get all database names.Get all databases.getDocument(String database, String collection, Bson filter) Get a document within a collection that match the given filter.Get a document within a collection that match the given filter, projections, and sort criteria.getDocuments(String database, String collection) Get all documents within a collection.getDocuments(String database, String collection, Bson filter) Get all documents within a collection that match the given filter.Get theMongoClientassociated with this Mongo Database connection.insertDocument(String database, String collection, Document document) Insert a document into a collection.insertDocuments(String database, String collection, List<Document> documents) Insert multiple documents into a collection.booleanopen()Opens a connection to the database.toString()Prints a representation of this MongoDatabase in string format, including the URI andMongoClientUpdate one or more documents within a collection that match the given filter, with the default update optionsupdateDocument(String database, String collection, Bson filter, List<Bson> updates, UpdateOptions updateOptions) Update one or more documents within a collection that match the given filter, with the provided update optionsupdateDocument(String database, String collection, Bson filter, Bson update) Update one or more documents within a collection that match the given filter, with the default update optionsupdateDocument(String database, String collection, Bson filter, Bson update, UpdateOptions updateOptions) Update one or more documents within a collection that match the given filter, with the provided update optionsUpdate multiple documents within a collection.updateDocuments(String database, String collection, Bson filter, List<Bson> update, UpdateOptions updateOptions) Update multiple documents within a collection.updateDocuments(String database, String collection, Bson filter, Bson update) Update multiple documents within a collection.updateDocuments(String database, String collection, Bson filter, Bson update, UpdateOptions updateOptions) Update multiple documents within a collection.Methods inherited from class dev.magicmq.pyspigot.manager.database.DatabasegetDatabaseId, getScript
- 
Constructor Details- 
MongoDatabase- Parameters:
- script- The script associated with this MongoDatabase
- clientSettings- The client settings for the MongoDatabase connection
 
 
- 
- 
Method Details- 
openpublic boolean open()Opens a connection to the database.
- 
closepublic boolean close()Closes a connection to the database.
- 
getMongoClientGet theMongoClientassociated with this Mongo Database connection.- Returns:
- The MongoClient
 
- 
fetchNewUpdateOptionsFetch a newUpdateOptionsobject for updates
- 
fetchNewFindOneAndUpdateOptionsFetch a newFindOneAndUpdateOptionsobject for updates
- 
createObjectCreate a new emptyBasicDBObject.- Returns:
- The BasicDBObject
 
- 
createObjectCreate a newBasicDBObjectout of the provided json.- Returns:
- The BasicDBObject
 
- 
createObjectCreate a newBasicDBObjectwith the provided key and value.- Returns:
- The BasicDBObject
 
- 
createDocumentCreate an emptyDocument.- Returns:
- The document
 
- 
createDocumentCreate aDocumentout of the provided json.- Parameters:
- json- A JSON representation of the document
- Returns:
- The document
 
- 
createDocumentCreate aDocumentwith the provided key and value.- Parameters:
- key- The key
- value- The value
- Returns:
- The document
 
- 
getDatabaseGet aMongoDatabasewith the given name.- Parameters:
- database- The name of the database
- Returns:
- The database
 
- 
getDatabaseNamesGet all database names.- Returns:
- An iterable list of type MongoIterable<String>containing all database names
 
- 
getDatabasesGet all databases.- Returns:
- An iterable list of type MongoIterable<Document>containing all databases
 
- 
doesDatabaseExistCheck if a database exists with the given name.- Parameters:
- database- The name of the database to check
- Returns:
- True if the database exists, false if otherwise
 
- 
createCollectionCreate a collection in the given database- Parameters:
- database- The name of the database where the collection should be created
- collection- The name for the collection
- Returns:
- True if the collection was created, false if it already exists in the database
 
- 
deleteCollectionDelete a collection in the given database- Parameters:
- database- The name of the database where the collection should be deleted
- collection- The name of the collection
- Returns:
- True if the collection was deleted, false if it did not exist in the database
 
- 
getCollectionGet a collection from a database.- Parameters:
- database- The name of the database to fetch from
- collection- The name of the collection to get
- Returns:
- A MongoCollection<Document>containingDocumentrepresenting the collection
 
- 
getCollectionNamesGet all collection names within a database.- Parameters:
- database- The database to get collections names from
- Returns:
- An iterable list of type ListCollectionNamesIterablecontaining all collection names
 
- 
getCollectionsGet all collections within a database.- Parameters:
- database- The database to get collections from
- Returns:
- An iterable list of type ListCollectionsIterable<Document>containing all collections
 
- 
doesCollectionExistCheck if a collection exists within a database.- Parameters:
- database- The name of the database to check
- collection- The name of the collection to check
- Returns:
- True if the collection exists, false if otherwise
 
- 
createCollectionIndexCreate a collection with an index of the given keys.- Parameters:
- database- The name of the database where the collection should be created
- collection- The name for the collection
- keys- A- Bsonobject representing the index keys
- Returns:
 
- 
getDocumentGet a document within a collection that match the given filter.- Parameters:
- database- The name of the database to fetch from
- collection- The name of the collection to fetch from
- filter- A- Bsonobject representing a filter to filter documents within the collection
- Returns:
- The first document within the collection that matched the provided filter
 
- 
getDocumentpublic Document getDocument(String database, String collection, Bson filter, Bson projections, Bson sorts) Get a document within a collection that match the given filter, projections, and sort criteria.- Parameters:
- database- The name of the database to fetch from
- collection- The name of the collection to fetch from
- filter- A- Bsonobject representing a filter to filter documents within the collection
- projections- The project document
- sorts- Sort criteria
- Returns:
- The first document within the collection that matched the provided filter, projections, and sort criteria
 
- 
getDocumentsGet all documents within a collection.- Parameters:
- database- The name of the database to fetch from
- collection- The name of the collection to fetch from
- Returns:
- An iterable list of type FindIterable<Document>containing all documents within the collection
 
- 
getDocumentsGet all documents within a collection that match the given filter.- Parameters:
- database- The name of the database to fetch from
- collection- The name of the collection to fetch from
- filter- A- Bsonobject representing a filter to filter documents within the collection
- Returns:
- An iterable list of type FindIterable<Document>containing all documents within the collection that matched the provided filter
 
- 
insertDocumentInsert a document into a collection.- Parameters:
- database- The database that contains the collection
- collection- The collection to insert into
- document- The document to insert
- Returns:
- An InsertOneResultrepresenting the outcome of the operation
 
- 
insertDocumentspublic InsertManyResult insertDocuments(String database, String collection, List<Document> documents) Insert multiple documents into a collection.- Parameters:
- database- The database that contains the collection
- collection- The collection to insert into
- documents- The documents to insert
- Returns:
- An InsertManyResultrepresenting the outcome of the operation
 
- 
updateDocumentUpdate one or more documents within a collection that match the given filter, with the default update options- Parameters:
- database- The database that contains the collection
- collection- The collection containing the document
- filter- A- Bsonobject representing a filter to filter documents within the collection
- update- The update that should be applied to the first matching document
- Returns:
- An UpdateResultrepresenting the outcome of the operation
 
- 
updateDocumentpublic UpdateResult updateDocument(String database, String collection, Bson filter, Bson update, UpdateOptions updateOptions) Update one or more documents within a collection that match the given filter, with the provided update options- Parameters:
- database- The database that contains the collection
- collection- The collection containing the document
- filter- A- Bsonobject representing a filter to filter documents within the collection
- update- The update that that should be applied to the first matching document
- updateOptions- A- UpdateOptionsobject representing the options to apply to the update operation
- Returns:
- An UpdateResultrepresenting the outcome of the operation
 
- 
updateDocumentpublic UpdateResult updateDocument(String database, String collection, Bson filter, List<Bson> updates) Update one or more documents within a collection that match the given filter, with the default update options- Parameters:
- database- The database that contains the collection
- collection- The collection containing the document
- filter- A- Bsonobject representing a filter to filter documents within the collection
- updates- The updates that should be applied to the first matching document
- Returns:
- An UpdateResultrepresenting the outcome of the operation
 
- 
updateDocumentpublic UpdateResult updateDocument(String database, String collection, Bson filter, List<Bson> updates, UpdateOptions updateOptions) Update one or more documents within a collection that match the given filter, with the provided update options- Parameters:
- database- The database that contains the collection
- collection- The collection containing the document
- filter- A- Bsonobject representing a filter to filter documents within the collection
- updates- The updates that should be applied to the first matching document
- updateOptions- A- UpdateOptionsobject representing the options to apply to the update operation
- Returns:
- An UpdateResultrepresenting the outcome of the operation
 
- 
findAndUpdateDocumentUpdate and return a document within a collection that match the given filter, with the default update options- Parameters:
- database- The database that contains the collection
- collection- The collection containing the document
- filter- A- Bsonobject representing a filter to filter documents within the collection
- update- The update that should be applied to the first matching document
- Returns:
- An UpdateResultrepresenting the outcome of the operation
 
- 
findAndUpdateDocumentpublic Document findAndUpdateDocument(String database, String collection, Bson filter, Bson update, FindOneAndUpdateOptions updateOptions) Update and return a document within a collection that match the given filter, with the default update options- Parameters:
- database- The database that contains the collection
- collection- The collection containing the document
- filter- A- Bsonobject representing a filter to filter documents within the collection
- update- The update that should be applied to the first matching document
- updateOptions- A- FindOneAndUpdateOptionsobject representing the options to apply to the update operation
- Returns:
- The document that was updated
 
- 
findAndUpdateDocumentpublic Document findAndUpdateDocument(String database, String collection, Bson filter, List<Bson> update) Update and return a document within a collection that match the given filter, with the default update options- Parameters:
- database- The database that contains the collection
- collection- The collection containing the document
- filter- A- Bsonobject representing a filter to filter documents within the collection
- update- The updates that should be applied to the first matching document
- Returns:
- The document that was updated
 
- 
findAndUpdateDocumentpublic Document findAndUpdateDocument(String database, String collection, Bson filter, List<Bson> update, FindOneAndUpdateOptions updateOptions) Update and return a document within a collection that match the given filter, with the default update options- Parameters:
- database- The database that contains the collection
- collection- The collection containing the document
- filter- A- Bsonobject representing a filter to filter documents within the collection
- update- The updates that should be applied to the first matching document
- updateOptions- A- FindOneAndUpdateOptionsobject representing the options to apply to the update operation
- Returns:
- The document that was updated
 
- 
updateDocumentsUpdate multiple documents within a collection.- Parameters:
- database- The database that contains the collection
- collection- The collection whose documents should be updated
- filter- A- Bsonobject representing a filter to filter documents within the collection
- update- The update that should be applied to all matching documents
- Returns:
- An UpdateResultrepresenting the outcome of the operation
 
- 
updateDocumentspublic UpdateResult updateDocuments(String database, String collection, Bson filter, Bson update, UpdateOptions updateOptions) Update multiple documents within a collection.- Parameters:
- database- The database that contains the collection
- collection- The collection whose documents should be updated
- filter- A- Bsonobject representing a filter to filter documents within the collection
- update- The update that should be applied to all matching documents
- updateOptions- A- UpdateOptionsobject representing the options to apply to the update operation
- Returns:
- An UpdateResultrepresenting the outcome of the operation
 
- 
updateDocumentspublic UpdateResult updateDocuments(String database, String collection, Bson filter, List<Bson> update) Update multiple documents within a collection.- Parameters:
- database- The database that contains the collection
- collection- The collection whose documents should be updated
- filter- A- Bsonobject representing a filter to filter documents within the collection
- update- The updates that should be applied to all matching documents
- Returns:
- An UpdateResultrepresenting the outcome of the operation
 
- 
updateDocumentspublic UpdateResult updateDocuments(String database, String collection, Bson filter, List<Bson> update, UpdateOptions updateOptions) Update multiple documents within a collection.- Parameters:
- database- The database that contains the collection
- collection- The collection whose documents should be updated
- filter- A- Bsonobject representing a filter to filter documents within the collection
- update- The updates that should be applied to all matching documents
- updateOptions- A- UpdateOptionsobject representing the options to apply to the update operation
- Returns:
- An UpdateResultrepresenting the outcome of the operation
 
- 
deleteDocumentDelete a document from a collection matching the provided filter.- Parameters:
- database- The database that contains the collection
- collection- The collection that contains the document
- filter- A- Bsonobject representing a filter to filter documents within the collection
- Returns:
- An DeleteResultrepresenting the outcome of the operation
 
- 
deleteDocumentsDelete multiple documents from a collection matching the provided filter.- Parameters:
- database- The database that contains the collection
- collection- The collection that contains the documents
- filter- A- Bsonobject representing a filter to filter documents within the collection
- Returns:
- An DeleteResultrepresenting the outcome of the operation
 
- 
toStringPrints a representation of this MongoDatabase in string format, including the URI andMongoClient
 
-