public interface MongoDBAPI
extends java.io.Closeable
限定符和类型 | 字段和说明 |
---|---|
static java.lang.String |
ID_FIELD |
限定符和类型 | 方法和说明 |
---|---|
<any> |
aggregate(java.lang.String collection,
java.util.List<? extends Bson> pipeline)
Aggregates documents according to the specified aggregation pipeline.
|
<T> <any> |
aggregate(java.lang.String collection,
java.util.List<? extends Bson> pipeline,
java.lang.Class<T> resultClass)
Aggregates documents according to the specified aggregation pipeline.
|
BulkWriteResult |
bulkWrite(java.lang.String collection,
java.util.List<? extends <any>> requests)
Executes a mix of inserts, updates, replaces, and deletes.
|
BulkWriteResult |
bulkWrite(java.lang.String collection,
java.util.List<? extends <any>> requests,
BulkWriteOptions options)
Executes a mix of inserts, updates, replaces, and deletes.
|
void |
close()
释放本连接占用的资源
|
boolean |
collectionExists(java.lang.String collectionName)
Check to see if a collection with a given name exists.
|
long |
count(java.lang.String collection)
Counts the number of documents in the collection.
|
long |
count(java.lang.String collection,
Bson filter)
Counts the number of documents in the collection according to the given options.
|
long |
count(java.lang.String collection,
Bson filter,
CountOptions options)
Counts the number of documents in the collection according to the given options.
|
void |
createCollection(java.lang.String collectionName)
Create an uncapped collection with the provided name.
|
void |
createCollection(java.lang.String collectionName,
CreateCollectionOptions createCollectionOptions)
Create a collection with the provided name and options.
|
DeleteResult |
deleteMany(java.lang.String collection,
Bson filter)
Removes all documents from the collection that match the given query filter.
|
DeleteResult |
deleteMany(java.lang.String collection,
Bson filter,
DeleteOptions options)
Removes all documents from the collection that match the given query filter.
|
DeleteResult |
deleteOne(java.lang.String collection,
Bson filter)
Removes at most one document from the collection that matches the given filter.
|
DeleteResult |
deleteOne(java.lang.String collection,
Bson filter,
DeleteOptions options)
Removes at most one document from the collection that matches the given filter.
|
<T> <any> |
distinct(java.lang.String collection,
java.lang.String fieldName,
Bson filter,
java.lang.Class<T> resultClass)
Gets the distinct values of the specified field name.
|
<T> <any> |
distinct(java.lang.String collection,
java.lang.String fieldName,
java.lang.Class<T> resultClass)
Gets the distinct values of the specified field name.
|
void |
dropCollection(java.lang.String collectionName)
Drop the collection with the given name.
|
<T> T |
execute(<any> action) |
<any> |
find(java.lang.String collection)
Finds all documents in the collection.
|
<any> |
find(java.lang.String collection,
Bson filter)
Finds all documents in the collection.
|
<T> <any> |
find(java.lang.String collection,
Bson filter,
java.lang.Class<T> resultClass)
Finds all documents in the collection.
|
<T> <any> |
find(java.lang.String collection,
java.lang.Class<T> resultClass)
Finds all documents in the collection.
|
Document |
find(java.lang.String collection,
java.lang.Object id,
java.lang.String... fetchFieldNames)
根据_id属性查找一行记录
|
Document |
find(java.lang.String collection,
java.lang.String idProperty,
java.lang.Object id,
java.lang.String... fetchFieldNames)
根据单一属性查找一行记录
|
Document |
findOneAndDelete(java.lang.String collection,
Bson filter)
Atomically find a document and remove it.
|
Document |
findOneAndDelete(java.lang.String collection,
Bson filter,
FindOneAndDeleteOptions options)
Atomically find a document and remove it.
|
Document |
findOneAndReplace(java.lang.String collection,
Bson filter,
Document replacement)
Atomically find a document and replace it.
|
Document |
findOneAndReplace(java.lang.String collection,
Bson filter,
Document replacement,
FindOneAndReplaceOptions options)
Atomically find a document and replace it.
|
Document |
findOneAndUpdate(java.lang.String collection,
Bson filter,
Bson update)
Atomically find a document and update it.
|
Document |
findOneAndUpdate(java.lang.String collection,
Bson filter,
Bson update,
FindOneAndUpdateOptions options)
Atomically find a document and update it.
|
<any> |
getCollection(java.lang.String collectionName)
Get a collection by name, creating it if it doesn't exist.
|
java.util.Set<java.lang.String> |
getCollectionNames()
A set of collection names.
|
void |
insertMany(java.lang.String collection,
java.util.List<? extends Document> documents)
Inserts one or more documents.
|
void |
insertMany(java.lang.String collection,
java.util.List<? extends Document> documents,
InsertManyOptions options)
Inserts one or more documents.
|
void |
insertOne(java.lang.String collection,
Document document)
Inserts the provided document.
|
void |
insertOne(java.lang.String collection,
Document document,
InsertOneOptions options)
Inserts the provided document.
|
<any> |
mapReduce(java.lang.String collection,
java.lang.String mapFunction,
java.lang.String reduceFunction)
Aggregates documents according to the specified map-reduce function.
|
<T> <any> |
mapReduce(java.lang.String collection,
java.lang.String mapFunction,
java.lang.String reduceFunction,
java.lang.Class<T> resultClass)
Aggregates documents according to the specified map-reduce function.
|
UpdateResult |
replaceOne(java.lang.String collection,
Bson filter,
Document replacement)
Replace a document in the collection according to the specified arguments.
|
UpdateResult |
replaceOne(java.lang.String collection,
Bson filter,
Document replacement,
UpdateOptions updateOptions)
Replace a document in the collection according to the specified arguments.
|
UpdateResult |
updateMany(java.lang.String collection,
Bson filter,
Bson update)
Update all documents in the collection according to the specified arguments.
|
UpdateResult |
updateMany(java.lang.String collection,
Bson filter,
Bson update,
UpdateOptions updateOptions)
Update all documents in the collection according to the specified arguments.
|
UpdateResult |
updateOne(java.lang.String collection,
Bson filter,
Bson update)
Update a single document in the collection according to the specified arguments.
|
UpdateResult |
updateOne(java.lang.String collection,
Bson filter,
Bson update,
UpdateOptions updateOptions)
Update a single document in the collection according to the specified arguments.
|
static final java.lang.String ID_FIELD
void createCollection(java.lang.String collectionName)
collectionName
- name of the collectionvoid createCollection(java.lang.String collectionName, CreateCollectionOptions createCollectionOptions)
collectionName
- name of the collectioncollectionOptions
- options to use when creating the collection.java.util.Set<java.lang.String> getCollectionNames()
<any> getCollection(java.lang.String collectionName)
collectionName
- name of the collectionboolean collectionExists(java.lang.String collectionName)
collectionName
- name of the collectionvoid dropCollection(java.lang.String collectionName)
collectionName
- name of the collection to drop/delete.<T> T execute(<any> action)
void close()
close
在接口中 java.lang.AutoCloseable
close
在接口中 java.io.Closeable
long count(java.lang.String collection)
long count(java.lang.String collection, Bson filter)
filter
- the query filterlong count(java.lang.String collection, Bson filter, CountOptions options)
filter
- the query filteroptions
- the options describing the count<T> <any> distinct(java.lang.String collection, java.lang.String fieldName, java.lang.Class<T> resultClass)
T
- the target type of the iterable.fieldName
- the field nameresultClass
- the class to cast any distinct items into.<T> <any> distinct(java.lang.String collection, java.lang.String fieldName, Bson filter, java.lang.Class<T> resultClass)
T
- the target type of the iterable.fieldName
- the field namefilter
- the query filterresultClass
- the class to cast any distinct items into.Document find(java.lang.String collection, java.lang.Object id, java.lang.String... fetchFieldNames)
collection
- id
- id值fetchFieldNames
- Document find(java.lang.String collection, java.lang.String idProperty, java.lang.Object id, java.lang.String... fetchFieldNames)
<any> find(java.lang.String collection)
<T> <any> find(java.lang.String collection, java.lang.Class<T> resultClass)
T
- the target document type of the iterable.resultClass
- the class to decode each document into<any> find(java.lang.String collection, Bson filter)
filter
- the query filter<T> <any> find(java.lang.String collection, Bson filter, java.lang.Class<T> resultClass)
T
- the target document type of the iterable.filter
- the query filterresultClass
- the class to decode each document into<any> aggregate(java.lang.String collection, java.util.List<? extends Bson> pipeline)
pipeline
- the aggregate pipeline<T> <any> aggregate(java.lang.String collection, java.util.List<? extends Bson> pipeline, java.lang.Class<T> resultClass)
T
- the target document type of the iterable.pipeline
- the aggregate pipelineresultClass
- the class to decode each document into<any> mapReduce(java.lang.String collection, java.lang.String mapFunction, java.lang.String reduceFunction)
mapFunction
- A JavaScript function that associates or "maps" a value with a key and emits the key and value pair.reduceFunction
- A JavaScript function that "reduces" to a single object all the values associated with a particular key.<T> <any> mapReduce(java.lang.String collection, java.lang.String mapFunction, java.lang.String reduceFunction, java.lang.Class<T> resultClass)
T
- the target document type of the iterable.mapFunction
- A JavaScript function that associates or "maps" a value with a key and emits the key and value pair.reduceFunction
- A JavaScript function that "reduces" to a single object all the values associated with a particular key.resultClass
- the class to decode each resulting document into.BulkWriteResult bulkWrite(java.lang.String collection, java.util.List<? extends <any>> requests)
requests
- the writes to executecom.mongodb.MongoBulkWriteException
- if there's an exception in the bulk write operationcom.mongodb.MongoException
- if there's an exception running the operationBulkWriteResult bulkWrite(java.lang.String collection, java.util.List<? extends <any>> requests, BulkWriteOptions options)
requests
- the writes to executeoptions
- the options to apply to the bulk write operationcom.mongodb.MongoBulkWriteException
- if there's an exception in the bulk write operationcom.mongodb.MongoException
- if there's an exception running the operationvoid insertOne(java.lang.String collection, Document document)
document
- the document to insertcom.mongodb.MongoWriteException
- if the write failed due some other failure specific to the insert commandcom.mongodb.MongoWriteConcernException
- if the write failed due being unable to fulfil the write concerncom.mongodb.MongoException
- if the write failed due some other failurevoid insertOne(java.lang.String collection, Document document, InsertOneOptions options)
document
- the document to insertoptions
- the options to apply to the operationcom.mongodb.MongoWriteException
- if the write failed due some other failure specific to the insert commandcom.mongodb.MongoWriteConcernException
- if the write failed due being unable to fulfil the write concerncom.mongodb.MongoCommandException
- if the write failed due to document validation reasonscom.mongodb.MongoException
- if the write failed due some other failurevoid insertMany(java.lang.String collection, java.util.List<? extends Document> documents)
bulkWrite
methoddocuments
- the documents to insertcom.mongodb.MongoBulkWriteException
- if there's an exception in the bulk write operationcom.mongodb.MongoException
- if the write failed due some other failurecom.mongodb.client.MongoCollection#bulkWrite
void insertMany(java.lang.String collection, java.util.List<? extends Document> documents, InsertManyOptions options)
bulkWrite
methoddocuments
- the documents to insertoptions
- the options to apply to the operationcom.mongodb.DuplicateKeyException
- if the write failed to a duplicate unique keycom.mongodb.WriteConcernException
- if the write failed due being unable to fulfil the write concerncom.mongodb.MongoException
- if the write failed due some other failureDeleteResult deleteOne(java.lang.String collection, Bson filter)
filter
- the query filter to apply the the delete operationcom.mongodb.MongoWriteException
- if the write failed due some other failure specific to the delete commandcom.mongodb.MongoWriteConcernException
- if the write failed due being unable to fulfil the write concerncom.mongodb.MongoException
- if the write failed due some other failureDeleteResult deleteOne(java.lang.String collection, Bson filter, DeleteOptions options)
filter
- the query filter to apply the the delete operationoptions
- the options to apply to the delete operationcom.mongodb.MongoWriteException
- if the write failed due some other failure specific to the delete commandcom.mongodb.MongoWriteConcernException
- if the write failed due being unable to fulfil the write concerncom.mongodb.MongoException
- if the write failed due some other failureDeleteResult deleteMany(java.lang.String collection, Bson filter)
filter
- the query filter to apply the the delete operationcom.mongodb.MongoWriteException
- if the write failed due some other failure specific to the delete commandcom.mongodb.MongoWriteConcernException
- if the write failed due being unable to fulfil the write concerncom.mongodb.MongoException
- if the write failed due some other failureDeleteResult deleteMany(java.lang.String collection, Bson filter, DeleteOptions options)
filter
- the query filter to apply the the delete operationoptions
- the options to apply to the delete operationcom.mongodb.MongoWriteException
- if the write failed due some other failure specific to the delete commandcom.mongodb.MongoWriteConcernException
- if the write failed due being unable to fulfil the write concerncom.mongodb.MongoException
- if the write failed due some other failureUpdateResult replaceOne(java.lang.String collection, Bson filter, Document replacement)
filter
- the query filter to apply the the replace operationreplacement
- the replacement documentcom.mongodb.MongoWriteException
- if the write failed due some other failure specific to the replace commandcom.mongodb.MongoWriteConcernException
- if the write failed due being unable to fulfil the write concerncom.mongodb.MongoException
- if the write failed due some other failureUpdateResult replaceOne(java.lang.String collection, Bson filter, Document replacement, UpdateOptions updateOptions)
filter
- the query filter to apply the the replace operationreplacement
- the replacement documentupdateOptions
- the options to apply to the replace operationcom.mongodb.MongoWriteException
- if the write failed due some other failure specific to the replace commandcom.mongodb.MongoWriteConcernException
- if the write failed due being unable to fulfil the write concerncom.mongodb.MongoException
- if the write failed due some other failureUpdateResult updateOne(java.lang.String collection, Bson filter, Bson update)
filter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.com.mongodb.MongoWriteException
- if the write failed due some other failure specific to the update commandcom.mongodb.MongoWriteConcernException
- if the write failed due being unable to fulfil the write concerncom.mongodb.MongoException
- if the write failed due some other failureUpdateResult updateOne(java.lang.String collection, Bson filter, Bson update, UpdateOptions updateOptions)
filter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.updateOptions
- the options to apply to the update operationcom.mongodb.MongoWriteException
- if the write failed due some other failure specific to the update commandcom.mongodb.MongoWriteConcernException
- if the write failed due being unable to fulfil the write concerncom.mongodb.MongoException
- if the write failed due some other failureUpdateResult updateMany(java.lang.String collection, Bson filter, Bson update)
filter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.com.mongodb.MongoWriteException
- if the write failed due some other failure specific to the update commandcom.mongodb.MongoWriteConcernException
- if the write failed due being unable to fulfil the write concerncom.mongodb.MongoException
- if the write failed due some other failureUpdateResult updateMany(java.lang.String collection, Bson filter, Bson update, UpdateOptions updateOptions)
filter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.updateOptions
- the options to apply to the update operationcom.mongodb.MongoWriteException
- if the write failed due some other failure specific to the update commandcom.mongodb.MongoWriteConcernException
- if the write failed due being unable to fulfil the write concerncom.mongodb.MongoException
- if the write failed due some other failureDocument findOneAndDelete(java.lang.String collection, Bson filter)
filter
- the query filter to find the document withDocument findOneAndDelete(java.lang.String collection, Bson filter, FindOneAndDeleteOptions options)
filter
- the query filter to find the document withoptions
- the options to apply to the operationDocument findOneAndReplace(java.lang.String collection, Bson filter, Document replacement)
filter
- the query filter to apply the the replace operationreplacement
- the replacement documentreturnOriginal
property, this will either be the
document as it was before the update or as it is after the update. If no documents matched the query filter, then null will be
returnedDocument findOneAndReplace(java.lang.String collection, Bson filter, Document replacement, FindOneAndReplaceOptions options)
filter
- the query filter to apply the the replace operationreplacement
- the replacement documentoptions
- the options to apply to the operationreturnOriginal
property, this will either be the
document as it was before the update or as it is after the update. If no documents matched the query filter, then null will be
returnedDocument findOneAndUpdate(java.lang.String collection, Bson filter, Bson update)
filter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.Document findOneAndUpdate(java.lang.String collection, Bson filter, Bson update, FindOneAndUpdateOptions options)
filter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.options
- the options to apply to the operationreturnOriginal
property, this will either be the
document as it was before the update or as it is after the update. If no documents matched the query filter, then null will be
returnedCopyright © Actionsoft Co., Ltd. All Rights Reserved.