Search code examples
mongodbbson

Is it OK to use the BSON Timestamp datatype?


According to the documentation:

The BSON timestamp type is for internal MongoDB use.

Ref.

Is this implying that I shouldn't use it or just advising that it's not a BsonDate?

(My question is, will I get shouted at for using it?)


Solution

  • The BSON Timestamp type is mainly intended for internal use by the MongoDB replication system and is documented for completeness.

    A general caveat on BSON types "for internal use" is that they are not expected to be extensively supported by drivers or server features. For example, BSON Timestamps cannot be used with Time-to-Live indexes or Date Aggregation Operators. MongoDB server code may also make assumptions about how internal field types like Timestamp should be treated, and possibly introduce behavioural changes to support expected internal use cases.

    Is this implying that I shouldn't use it or just advising that it's not a BsonDate?

    The MongoDB documentation is strongly implying that you use the BSON Date type for your application development to avoid potential issues.

    There may be cases where you need to work with Timestamp values (for example, if you wanted to develop a script to work with timestamps in a MongoDB replica set oplog), but you should avoid relying on the BSON Timestamp type or behaviour for your own use cases.