Interface NitriteCollection
- All Superinterfaces:
org.dizitart.no2.common.meta.AttributesAware,AutoCloseable,EventAware,PersistentCollection<Document>
NitriteId in 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 CollectionEventListener.
Nitrite db = Nitrite.builder()
.openOrCreate("user", "password");
NitriteCollection collection = db.getCollection("products");
- Since:
- 1.0
- Author:
- Anindya Chatterjee
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault 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 DocumentCursorApplies a filter on the collection and returns a cursor to the selected documents.find(Filter filter, FindOptions findOptions) Applies a filter on the collection and returns a customized cursor to the selected documents.Gets a single element from the collection by its id.getName()Returns the name of theNitriteCollection.default WriteResultInserts documents into a collection.default WriteResultRemoves matching elements from the collection.Removes document from a collection.default WriteResultUpdate documents in the collection.update(Filter filter, Document update, UpdateOptions updateOptions) Updates document in the collection.Methods inherited from interface org.dizitart.no2.common.meta.AttributesAware
getAttributes, setAttributesMethods inherited from interface org.dizitart.no2.collection.events.EventAware
subscribe, unsubscribeMethods 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 Details
-
insert
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:
-
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
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:
-
remove
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
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
Returns a cursor to all documents in the collection.- Returns:
- a cursor to all documents in the collection.
-
find
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:
-
find
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:
-
find
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
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.
-