Interface NitriteCollection
-
- All Superinterfaces:
org.dizitart.no2.common.meta.AttributesAware,AutoCloseable,EventAware,PersistentCollection<Document>
public interface NitriteCollection extends PersistentCollection<Document>
Represents a named document collection stored in Nitrite database. It persists documents into the database. Each document is associated with a uniqueNitriteIdin a collection.A nitrite collection supports indexing. Every nitrite collection is also observable. It means, any change in a collection can be listened back via registering a
Create a collectionCollectionEventListener.Nitrite db = Nitrite.builder() .openOrCreate("user", "password"); NitriteCollection collection = db.getCollection("products");- Since:
- 1.0
- Author:
- Anindya Chatterjee
- See Also:
EventAware,Document,NitriteId,CollectionEventListener,EventBus
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default DocumentCursorfind()Returns a cursor to all documents in the collection.default DocumentCursorfind(FindOptions findOptions)Returns a customized cursor to all documents in the collection.default DocumentCursorfind(Filter filter)Applies a filter on the collection and returns a cursor to the selected documents.DocumentCursorfind(Filter filter, FindOptions findOptions)Applies a filter on the collection and returns a customized cursor to the selected documents.DocumentgetById(NitriteId nitriteId)Gets a single element from the collection by its id.StringgetName()Returns the name of theNitriteCollection.default WriteResultinsert(Document document, Document... documents)Inserts documents into a collection.default WriteResultremove(Filter filter)Removes matching elements from the collection.WriteResultremove(Filter filter, boolean justOne)Removes document from a collection.default WriteResultupdate(Filter filter, Document update)Update documents in the collection.WriteResultupdate(Filter filter, Document update, UpdateOptions updateOptions)Updates document in the collection.-
Methods inherited from interface org.dizitart.no2.common.meta.AttributesAware
getAttributes, setAttributes
-
Methods inherited from interface org.dizitart.no2.collection.events.EventAware
subscribe, unsubscribe
-
Methods inherited from interface org.dizitart.no2.common.PersistentCollection
addProcessor, clear, close, createIndex, createIndex, drop, dropAllIndices, dropIndex, getStore, hasIndex, insert, isDropped, isIndexing, isOpen, listIndices, rebuildIndex, remove, size, update, update
-
-
-
-
Method Detail
-
insert
default WriteResult insert(Document document, Document... documents)
Inserts documents into a collection. If the document contains aNitriteIdin its_idfield, then it will be used as a unique key to identify the document in the collection. If the document does not contain anyNitriteId, then a newNitriteIdwill be generated and inserted into the document.If any of the field is already indexed in the collection, then after insertion the index will also be updated.
NOTE: These operations will notify all
CollectionEventListenerinstances registered to this collection with change typeEventType.Insert.- Parameters:
document- the document to insertdocuments- other documents to insert in a batch.- Returns:
- the result of write operation.
- Throws:
ValidationException- ifdocumentisnull.InvalidIdException- if the_idvalue contains non comparable type, i.e. type that does not implementComparable.UniqueConstraintException- if the value of_idvalue clashes with the id of another document in the collection.UniqueConstraintException- if a field of the document is indexed and it violates the unique constraint in the collection(if any).- See Also:
NitriteId,WriteResult
-
update
default WriteResult update(Filter filter, Document update)
Update documents in the collection.If the
filterisnull, it will update all documents in the collection.NOTE: This operations will notify all
CollectionEventListenerinstances registered to this collection with change typeEventType.Update.- Parameters:
filter- the filter to apply to select documents from the collection.update- the modifications to apply.- Returns:
- the result of the update operation.
- Throws:
ValidationException- if theupdatedocument isnull.
-
update
WriteResult update(Filter filter, Document update, UpdateOptions updateOptions)
Updates document in the collection. Update operation can be customized with the help ofupdateOptions.If the
filterisnull, it will update all documents in the collection unlessjustOnceis set totrueinupdateOptions.NOTE: This operations will notify all
CollectionEventListenerinstances registered to this collection with change typeEventType.UpdateorEventType.Insert.- Parameters:
filter- the filter to apply to select documents from the collection.update- the modifications to apply.updateOptions- the update options to customize the operation.- Returns:
- the result of the update operation.
- Throws:
ValidationException- if theupdatedocument isnull.ValidationException- ifupdateOptionsisnull.- See Also:
UpdateOptions
-
remove
default WriteResult remove(Filter filter)
Removes matching elements from the collection.If the
filterisnull, it will remove all objects from the collection.NOTE: This operations will notify all
CollectionEventListenerinstances registered to this collection with change typeEventType.Remove.- Parameters:
filter- the filter to apply to select elements from collection.- Returns:
- the result of the remove operation.
-
remove
WriteResult remove(Filter filter, boolean justOne)
Removes document from a collection. Remove operation can be customized byremoveOptions.If the
filterisnull, it will remove all documents in the collection unlessjustOnceis set totrueinremoveOptions.NOTE: This operations will notify all
CollectionEventListenerinstances registered to this collection with change typeEventType.Remove.- Parameters:
filter- the filter to apply to select documents from collection.justOne- indicates if only one element will be removed or all of them.- Returns:
- the result of the remove operation.
-
find
default DocumentCursor find()
Returns a cursor to all documents in the collection.- Returns:
- a cursor to all documents in the collection.
-
find
default DocumentCursor find(Filter filter)
Applies a filter on the collection and returns a cursor to the selected documents.See
Filterfor all available filters.NOTE: If there is an index on the value specified in the filter, this operation will take advantage of the index.
- Parameters:
filter- the filter to apply to select documents from collection.- Returns:
- a cursor to all selected documents.
- Throws:
ValidationException- iffilteris null.- See Also:
Filter,DocumentCursor.project(Document)
-
find
default DocumentCursor find(FindOptions findOptions)
Returns a customized cursor to all documents in the collection.- Parameters:
findOptions- specifies pagination, sort options for the cursor.- Returns:
- a cursor to all selected documents.
- See Also:
SortOrder
-
find
DocumentCursor find(Filter filter, FindOptions findOptions)
Applies a filter on the collection and returns a customized cursor to the selected documents.NOTE: If there is an index on the value specified in the filter, this operation will take advantage of the index.
- Parameters:
filter- the filter to apply to select documents from collection.findOptions- specifies pagination, sort options for the cursor.- Returns:
- a cursor to all selected documents.
-
getById
Document getById(NitriteId nitriteId)
Gets a single element from the collection by its id. If no element is found, it will returnnull.- Parameters:
nitriteId- the nitrite id- Returns:
- the unique document associated with the nitrite id.
- Throws:
ValidationException- if `nitriteId` isnull.
-
getName
String getName()
Returns the name of theNitriteCollection.- Returns:
- the name.
-
-