MongoCollection¶
Description¶
Represents a server side document grouping within a MongoDB database.
Method Descriptions¶
find¶
func find(filter: Dictionary, options: Dictionary)
Finds the documents in this collection which match the provided filter.
Parameters
- filter: Dictionary representing a document that should match the query
- options: Optional arguments
Returns: Array of documents or error Dictionary
find_one¶
func find_one(filter: Dictionary, options: Dictionary)
Finds a single document in this collection that match the provided filter.
Parameters
- filter: Dictionary representing a document that should match the query
- options: Optional arguments
Returns: An optional document that matched the filter or error Dictionary
find_one_and_delete¶
func find_one_and_delete(filter: Dictionary, options: Dictionary)
Finds a single document matching the filter, deletes it, and returns the original.
Parameters
- filter: Dictionary representing a document that should be deleted
- options: Optional arguments
Returns: The document that was deleted or error Dictionary
find_one_and_replace¶
func find_one_and_replace(filter: Dictionary, doc: Dictionary, options: Dictionary)
Finds a single document matching the filter, replaces it, and returns either the original or the replacement document.
Parameters
- filter: Dictionary representing a document that should be replaced
- doc: Dictionary representing the replacement for a matching document
- options: Optional arguments
Returns: The original or replaced document or error Dictionary
find_one_and_update¶
func find_one_and_update(filter: Dictionary, doc: Dictionary, options: Dictionary)
Finds a single document matching the filter, updates it, and returns either the original or the newly-updated document.
Parameters
- filter: Dictionary representing a document that should be updated
- options: Optional arguments
Returns: The original or updated document or error Dictionary
insert_one¶
func insert_one(doc: Dictionary, options: Dictionary)
Inserts a single document into the collection.
If the document is missing an identifier (_id field) one will be generated for it.
Parameters
- doc: The document to insert
- options: Optional arguments
Returns: The result of attempting to perform the insert or error Dictionary
insert_many¶
func insert_many(docs: Array, options: Dictionary)
Inserts multiple documents into the collection.
If the documents are missing identifiers then they will be generated for them.
Parameters
- doc: Array of documents to insert
- options: Optional arguments
Returns: The result of attempting to performing the insert or error Dictionary
replace_one¶
func replace_one(filter: Dictionary, doc: Dictionary, options: Dictionary)
Replaces a single document matching the provided filter in this collection.
Parameters
- filter: Document representing the match criteria
- doc: The replacement document
- options: Optional arguments
Returns: The result of attempting to replace a document or error Dictionary
update_one¶
func update_one(filter: Dictionary, doc_or_pipeline, options: Dictionary)
Updates a single document matching the provided filter in this collection.
Parameters
- filter: Document representing the match criteria
- doc: Document representing the update to be applied to a matching document
- options: Optional arguments
Returns: The result of attempting to update a document or error Dictionary
update_many¶
func update_many(filter: Dictionary, doc_or_pipeline, options: Dictionary)
Updates multiple documents matching the provided filter in this collection.
Parameters
- filter: Document representing the match criteria
- doc: Document representing the update to be applied to the matching documents
- options: Optional arguments
Returns: The result of attempting to update multiple documents or error Dictionary
delete_one¶
func delete_one(filter: Dictionary, options: Dictionary)
Deletes a single matching document from the collection.
Parameters
- filter: Dictionary representing the data to be deleted
- options: Optional arguments
Returns: The result of performing the deletion or error Dictionary
delete_many¶
func delete_many(filter: Dictionary, options: Dictionary)
Deletes all matching documents from the collection.
Parameters
- filter: Dictionary representing the data to be deleted
- options: Optional arguments
Returns: The result of performing the deletion or error Dictionary
rename¶
func rename(name: String, drop_target_before_rename = false)
Rename this collection.
Parameters
- name: The new name to assign to the collection
- drop_target_before_rename: Whether to overwrite any existing collections called new_name. The default is false.
Returns: True if success or error Dictionary
get_name¶
func get_name()
Returns the name of this collection.
Returns: The name of this collection
drop¶
func drop()
Drops this collection and all its contained documents from the database.
Returns: True if success or error Dictionary
count_documents¶
func count_documents(filter: Dictionary, options)
Counts the number of documents matching the provided filter.
Parameters
- filter: The filter that documents must match in order to be counted
- options: Optional arguments
Returns: The count of the documents that matched the filter or error Dictionary
estimated_document_count¶
func estimated_document_count(options: Dictionary)
Returns an estimate of the number of documents in the collection.
Parameters
- options: Optional arguments
Returns: The count of the documents that matched the filter or error Dictionary
create_index¶
func create_index(index: Dictionary, options: Dictionary)
Creates an index over the collection for the provided keys with the provided options.
Parameters
- index: Dictionary representing the 'keys' and 'options' of the new index
- options: Optional arguments
Returns: Dictionary or error Dictionary
get_indexes¶
func get_indexes()
Returns a MongoIndex for this collection
Returns: MongoIndex for this collection or error Dictionary
get_indexes_list¶
func get_indexes_list()
Returns a list of the indexes currently on this collection.
Returns: Array of indexes or error Dictionary
get_distinct¶
func get_distinct(name: String, filter: Dictionary, options: Dictionary)
Finds the distinct values for a specified field across the collection.
Parameters
- name: The field for which the distinct values will be found
- filter: ictionary representing the documents for which the distinct operation will apply
- options: Optional arguments
Returns: Array of the distinct values or error Dictionary