couchbaselabs / node-ottoman

Node.js ODM for Couchbase
https://ottomanjs.com/
Apache License 2.0
287 stars 98 forks source link

maxExpiry doesnt seem to work on creating or updating documents #708

Closed Angusross111 closed 1 year ago

Angusross111 commented 1 year ago

I have tried using the maxExpiry option on Model.create, Model.updateById, CreateModelOptions when creating the model as well as some of the other places. None seem to work, every document going into my collection still have there meta.expiration set to 0. Is it possible to set individual documents with an expiry/TTL ? The collection was created with the maxExpiry as 0.

gsi-alejandro commented 1 year ago

hi @Angusross111

maxExpiry option is working when creating a collection, check the code below to set the expiry time at the model level:

const schema = new Schema({
    name: String,
  });
  const collectionName = 'maxExpiryCollection';
  const MaxExpiryModel = model<{ name: string }>(collectionName, schema, { maxExpiry: 5 });

Note: In this example maxExpiry (in seconds) will be used as an option to create the collection, therefore all documents in this collection will be removed after the maxExpiry value.

gsi-alejandro commented 1 year ago

@Angusross111

Yes, It's possible to set individual expiry/TTL: Model functions:

Document functions:

I'm checking it, due to it's not working currently.

In the next version, we will release a fix to it.

gsi-alejandro commented 1 year ago

Hi @Angusross111

These changes were released in version 2.3.2