# PyMongo: NotImplementedError: Database objects do not implement truth value testing or bool(). Please compare with None instead: database is not None

**Code:** `NotImplementedError: Collection objects do not implement truth value testing` · **Category:** MongoDB · **Seen on:** MongoDB, Python

You used a Database/Collection object in an `if` (`if db:`), which PyMongo forbids.

## Meaning

Compare explicitly: `if db is not None:`. PyMongo 4+ raises this to avoid ambiguous truthiness. Update patterns such as `db = client.db or default` and `if collection:`.

## Common causes

- `if db:` / `if collection:` / `x or y` on a Database or Collection
- Code written for PyMongo 3
- Optional dependency checks
- Cached connection checks
- Conditional default assignments

## Quick fix

1. `if db is not None:`
2. Use explicit sentinel checks
3. Search your code for `if collection` / `if db`

## Detailed fix by platform

### Python

1. `if collection is None: collection = client["app"]["users"]`

## How to diagnose

1. **Pattern** — Truthiness used?
2. **Replace** — is None?
3. **Version** — PyMongo 4?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/mongodb/pymongo-collection-truth-value-testing)
