validate() (Validate Collection Integrity)
Last updated: 2026-10-09
validate() (Validate Collection Integrity)
validate() checks a collection's structural integrity, e.g. `db.users.validate({ full: true })`. It scans the collection's BSON documents and indexes, reporting corruption or check failures — commonly run during troubleshooting or before upgrades. full: true deepens the check at the cost of time. The result's valid field is true when data is sound.
| Category | Index & Admin |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
db.<collection>.validate({ full: <bool> })
⚙️ Parameters
| full | Optional. true runs a deeper scan including indexes; default false. |
|---|
Returns:Validation report with valid, ns, nrecords, etc.
▶ Example
Run the commands below in your local mongosh (requires a running mongod):
// validate: check integrity of the users collection
const report = db.users.validate({ full: false })
print('valid: ' + report.valid)
Output:
valid: true
📌 Notes
- Running it on huge collections is resource-heavy — prefer off-peak
- full: true takes longer but is more thorough
- On corruption, restore from backup instead of hand-editing data files
🏷️ Related Tags
💡 Related Cases
Deleting Documents and Getting Started with Node.js
Mongoose Models and Schema Design
Mongoose Data Validation and Middleware
📚 Related Tutorials
❓ FAQ
QWhat does the full option of validate do?
Afull: true adds deep checks of indexes and internals — more thorough but noticeably slower.
QWhat is the valid field in validate's result?
Avalid reports whether the data passed: true means sound, false signals corruption.
QWhat should I do when validation finds corruption?
AStop writes immediately, restore from the latest backup, and inspect disk/hardware health.