是否可使用BSON Timestamp数据类型?对其MongoDB内部用途标注存疑
Hey there, let’s cut through the ambiguity here so you know exactly where you stand.
First, let’s revisit the documentation note you mentioned:
BSON timestamp type is for internal MongoDB use.
This isn’t a strict prohibition—it’s a contextual heads-up about the type’s intended purpose. MongoDB built BSON Timestamps specifically for internal operations like replication and oplog tracking, where it needs a strictly ordered, operation-specific sequence (this is why it’s distinct from BsonDate, which is designed for general-purpose date/time storage).
Now, to your core question: Will you get "called out" for using it? It all comes down to your use case:
If you’re using it as a replacement for
BsonDate: This is where you might push back from other developers.BsonDateis the standard for storing real-world timestamps (like user sign-up times, event triggers), and it has universal support across MongoDB drivers, UIs, and query tools—everyone expects it for date-related data. Using a Timestamp here would confuse your team, break readability, and cause headaches with things like date range queries or reporting.If you’re using it for a use case matching its internal design: For example, if you’re building a custom replication workflow, tracking ordered system operations that need to align with MongoDB’s internal timing, or any scenario where you need that exact 64-bit structure (32 bits for epoch seconds, 32 bits for an incrementing operation ordinal), then this makes perfect sense. Experienced MongoDB developers will recognize this as a deliberate, appropriate choice—you’re using the tool for what it was built to do, even if it’s labeled "internal".
A quick best practice tip: Unless you have a specific, technical reason to use BSON Timestamp, stick with BsonDate for all general timestamp needs. It’s more intuitive, better supported, and avoids any unnecessary confusion.
内容的提问来源于stack exchange,提问作者BanksySan

