How to create the collection with time stamp #95
Copy link
Copy link
Closed
Description
Activity
The existing
Mongoc.write_commandmethod can send MongoDB'screatecommand 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
DateTimevalues 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.
Metadata
Metadata
Assignees
Labels
No labels
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