Skip to content

How to create the collection with time stamp #95

Description

@nilesh81996

Hi,
This is the first time I am using mongoDB and Julia, I want to create a time series collection using Julia, but I cant find the method equivalent to db.createCollection() which is mentioned on MongoDB website

Activity

  1. quinnj commented on Oct 4, 2026

    @quinnj
    Member

    The existing Mongoc.write_command method can send MongoDB's create command with time-series options:

    import Mongoc
    using Dates
    
    client = Mongoc.Client("mongodb://localhost:27017")
    database = client["time_series"]
    Mongoc.write_command(database, Mongoc.BSON(
        "create" => "measurements",
        "timeseries" => Dict(
            "timeField" => "timestamp",
            "metaField" => "sensor",
            "granularity" => "minutes",
        ),
    ))
    collection = database["measurements"]
    Mongoc.insert_one(collection, Mongoc.BSON(
        "timestamp" => DateTime(2022, 1, 1),
        "sensor" => "A",
        "temperature" => 21,
    ))

    Use a new collection name. MongoDB requires feature compatibility version 5.0 or later for time-series collections, and the time field must contain a BSON date. Julia DateTime values encode as BSON dates. See the MongoDB time-series guide.

    Verified against current master 179b73bedb20a5adc58521a26298bda9afb6852e, MongoDB 5.0.33 and libmongoc 1.30.8 on Linux, with Julia 1.6.7 and 1.13.1. All 20 checks pass on each runtime, including the created collection's options, insertion, date filtering and aggregation. Closing this usage question with the working API example.

    AI disclosure: This work was prepared with assistance from OpenAI Codex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions