Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

305
Vistas
How do we create timeseries collections with mongodb golang driver?

I am trying to create timeseries collections => https://www.mongodb.com/developer/how-to/new-time-series-collections/#expireafterseconds with the following function As you can see below i have tried different iterations to pass options to the CreateCollection() but nothing works. Searched for hours for an example of this and could not find any, and one would think will be easy to setup based on current documentation but hours later and here to get help

func CollectionsTimeSeries(name string) {

    ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)

    // options := {
    //  "TimeSeriesOptions": {
    //      "TimeField": "time_stamp",
    //      "MetaField": "stock",
    //      "Granularity": "minutes",
    //  },
    //  "ExpireAfterSeconds": 2592000,      
    // }

    // options := { 
    //  timeseries: {
    //      timeField: "time_stamp",
    //      metaField: "stock",
    //      granularity: "minutes",
    //  },
    //  expireAfterSeconds: 2592000         
    // }

    options := { 
    "timeseries": {
        "timeField": "time_stamp",
        "metaField": "stock",
        "granularity": "minutes",
    },
    "expireAfterSeconds": 2592000       
    }

    // database.GetConnection.CreateCollection(ctx, name, { 
    //  timeseries: {
    //      timeField: "time_stamp",
    //      metaField: "stock",
    //      granularity: "minutes",
    //  },
    //  expireAfterSeconds: 2592000         
    // })


    database.GetConnection.CreateCollection(ctx, name, options)
}

Get the following errors

syntax error: unexpected {, expecting expression
syntax error: unexpected }, expecting comma or )
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Use the options package to create an options instance containing time series options:

opt:=options.CreateCollection().
   SetTimeseriesOptions(options.TimeSeries().
        SetGranularity("...").
        SetMetaField("...").
        SetTimeField("..."))
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda