Long (64-bit Integer)

Last updated: 2026-10-09

Long (64-bit Integer)

Long is a signed 64-bit integer (BSON type int64), roughly ±9.2×10^18, constructed with `Long(42)` or the alias `NumberLong(42)`. Use it for millisecond timestamps, big counters, and large ids. Values beyond JavaScript's safe integer (about 9×10^15) must be built from strings to avoid precision loss.

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

📝 Syntax

Long(<integer>)
Long("<large number string>")
NumberLong("9223372036854775807")

Returns:Returns a Long (int64) BSON integer

▶ Example

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

// Long: 64-bit large integer
use shop
db.stats.insertOne({ total: Long('9223372036854775807') })
db.stats.find({ total: { $gt: Long(1000) } })

Output:

{ _id: ObjectId('...'), total: Long('9223372036854775807') }

📌 Notes

📚 Related Tutorials

❓ FAQ

QIs Long the same as NumberLong?
ANo — NumberLong is mongosh's alias for Long; both produce the int64 type.
QHow large can a Long hold?
ASigned 64-bit, about ±9.2×10^18 — far beyond JS's safe integer range.
QWhy construct Long from a string?
ANumeric literals above ~9×10^15 lose precision in JS; string construction stays exact.
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%

🙏 帮我们做得更好

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

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