API Reference
no

def no(predicate: Union[str, QueryObject], /) -> TagSet

Create a negative predicate (NOT condition) for find queries.

Allows to exclude objects that match the given predicate, enabling filtering out unwanted objects based on tags or query results. This is particularly useful for finding objects that have one tag but not another, or for calculating the difference between two query results over time (e.g., finding newly added or recently deleted items).

Parameters

  • predicate str or QueryObject
    The condition to negate. This can be a string tag or a query object, which is often the result of another find query.

Returns

A predicate object representing logical NOT operation.


Examples

Exclude by tag

You can find all objects that have the active-project tag but exclude those that are also marked as on-hold.

# Find projects that are active but not on hold
active_not_on_hold = db0.find("active-project", db0.no("on-hold"))
 
for project in active_not_on_hold:
    print(f"Active project: {project.name}")

Complex exclusions

You can use dbzero.no() with query results to exclude entire sets of objects.

# Find objects with tag1 but not in a specific result set
excluded_set = db0.find("excluded-group")
filtered = db0.find("tag1", db0.no(excluded_set))

Calculate query deltas

It is common to compare two snapshots to see what has changed. For example, you can find all objects that were returned by a query in a new snapshot (snap2) but were not present in the results from an older snapshot (snap1).

# In snap1, there are objects with value 1 and 2
query_1 = snap1.find("some-tag") # Result contains objects with value 1, 2
 
# In snap2, objects with value 1 was untagged, and objects 3, 4 were added
query_2 = snap2.find("some-tag") # Result contains objects with value 2, 3, 4
 
# Find objects that are in query_2 but NOT in query_1
newly_added = snap2.find(query_2, db0.no(query_1))
# newly_added will contain objects with value 3, 4
 
# Find objects that were in query_1 but are NOT in query_2
deleted = snap1.find(query_1, db0.no(query_2))
# deleted will contain the object with value 1