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.

CategoryIndex & Admin
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

db.<collection>.validate({ full: <bool> })

⚙️ Parameters

fullOptional. 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

📚 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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏