How to insert a time series document using Mongoose (NodeJS)

Hi all,

I’m trying to insert a time series document, but it throws the error “‘timestamp’ must be present and contain a valid BSON UTC datetime value”.

However, my document has a ‘timestamp’ field and it is in the format of a unix number with milliseconds (e.g. 1733824264000).

Based on the documentation linked below, this should be correct. What am I missing here?

Hi @Douwe_Kerstens,

Can you add your current code to the question?

1 Like

Hi NeNaD,

I’ve made it work by making the ‘timestamp’ field a js Date instead of a number.

Note that in the code snippet below, the variable ‘timestamp’ is a dayjs-generated unix timestamp without milliseconds, whereas the js Date ctor needs milliseconds, hence the * 1000, and ‘model’ is the model for the relevant timeseries collection.

I have tried putting in a unix timestamp with and without milliseconds, both resulted in the same error.

    const event: Event = {
      timestamp: new Date(timestamp * 1000),
      // other fields,
    };

    model.create(event);

Is there a piece of documentation that I missed, that says the timeField should be a js Date?