jeroen / mongolite

Fast and Simple MongoDB Client for R
https://jeroen.github.io/mongolite/
284 stars 64 forks source link

How to create a Collection with a schema (timeseries) #231

Closed Wesseldr closed 2 years ago

Wesseldr commented 2 years ago

I'm trying to run the following command:

db.createCollection("weather", { timeseries: { timeField: "timestamp" } } )

I tried several variations with the mongo$run command but that seems to always return unknown command. I had hope that this issue with creating an unique index could be transformed: https://github.com/jeroen/mongolite/issues/133#issuecomment-623007310

m <- mongolite::mongo(mongo_url, collection = 'col', db = 'test') mongo_connection$run('{"createIndexes": "col", "indexes":[{"key":{"field_A":1, "field_B": 1}, "name": "field_A_B_index", "unique": true]}')

Hope someone has done this before and knows a way :-)

Wesseldr commented 2 years ago

Got it :-)

m$run('{ "create": "weather", "timeseries": { "timeField": "timestamp" }}') I'll leave the question here for others to find when looking for ways to create a timeseries collection