Unable to have 2 unique field together in timeseries collection

hey guys i am new to mongo db
we are using mongo db for recording candlestick information with timeseries collection

but we want to avoid duplicate data
i created a time series collection:

db.createCollection(
    "timeseries_5",
    {
       timeseries: {
          timeField: "timestamp",
          metaField: "symbol",
          granularity: "seconds"
       }
    }
)

i created my index

db.timeseries_5.createIndex(
{   
    "timestamp": 1,
    "symbol": 1
    
},
    {
        name: "symbol_timestamp",
        sparse: true
    }
);

but i can pass unique:true

{
"message" : "Unique indexes are not supported on collections clustered by _id",
"ok" : 0,
"code" : 72,
"codeName" : "InvalidOptions"
}

how i avoid duplicate data in mongo db timeseries collection???
i need unique 2 field (symbol, timestamp)

this is how i insert my data

db.timeseries_5.insert([{
    
    timestamp: ISODate('2019-01-01T13:15:00.000Z'),
    symbol: 'SNX',

    metadata:{
        open: 0.040613,
        high: 0.040613,
        volume: 3286.08613337,
        close: 0.040123,
        exchange: 'kucoin',
        low: 0.039847,
    }
    }])
1 Like

Hi,
Unique Index is not possible in Timeseries for now:

"
These index types aren’t supported:

  • [Text]
  • [2d]

These index properties aren’t supported:

  • [TTL]
  • [Unique] "

I hope it’s will be changed in next released.

best regards,

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.