Int32 (32-bit Integer)

Last updated: 2026-10-09

Int32 (32-bit Integer)

Int32 is a signed 32-bit integer, ranging from -2147483648 to 2147483647. In mongosh a bare number like 42 is a Double, so construct integers explicitly with `Int32(42)`. Use it for ages, counters, and ids that stay small; switch to Long beyond 32-bit range.

CategoryBSON Types
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

Int32(<integer>)
{ age: Int32(30) }
db.users.find({ age: { $gt: Int32(18) } })

Returns:Returns an Int32 BSON integer

▶ Example

Run the commands below in your local mongosh (requires a running mongod):

// Int32: construct an integer explicitly
use shop
db.users.insertOne({ name: 'alice', age: Int32(30) })
db.users.find({ age: { $gt: Int32(18) } })

Output:

{ _id: ObjectId('...'), name: 'alice', age: Int32(30) }

📌 Notes

📚 Related Tutorials

❓ FAQ

QInt32 or Long — how to choose?
AStay within ±2.1 billion with Int32; use Long (64-bit) beyond that or for growth headroom.
QWhat type is 42 in mongosh?
AIt is a Double by default. Use Int32(42) or Long(42) for an integer.
QCan Int32 overflow?
AYes — constructing a value beyond 32-bit range errors; switch to Long.
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%

🙏 帮我们做得更好

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

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