bwgjoseph / mongoose-vs-ottoman

feature comparison between mongoose and ottoman
0 stars 1 forks source link

maxExpiry #94

Closed bwgjoseph closed 3 years ago

bwgjoseph commented 3 years ago

Hi,

Would like to check maxExpiry in ModelOptions and what does it mean exactly

The explanation given in the doc is

maxExpiry: value used to create a collection for this instance. The default value is 300000.

And based on what I understand/know, that seems to be to indicate the TTL of the document? Does this mean to say after 5 mins, the document will be automatically removed?

During my test, that doesn't seem to be the case.

// created a model and set to 10000
const modelName = 'posts';
  const modelOptions: ModelOptions = {
    scopeName: 'postscope',
    collectionName: 'postcollection',
    maxExpiry: 10000,
  };

  const schema = new Schema({
    title: {
      type: String,
      required: true,
    }
  }).add(baseSchema);

  return getModel(modelName) || model(modelName, schema, modelOptions);

// check the metadata after doc is created
// expiration is 0, which i assume is unlimited
{
  "meta": {
    "id": "posts::3fccd44d-aa7d-4ec7-894f-0be5f529edba",
    "rev": "9-16880979ac7200000000000002000000",
    "expiration": 0,
    "flags": 33554432,
    "type": "json"
  },
  "xattrs": {}
}

So may I know what is that maxExpiry option is used for? How do I use TTL feature if I want to?

AV25242 commented 3 years ago

@bwgjoseph yeah maxExpiry is the means to add TTL at a collection level. You are right currently maxExpiry defaults to 5 minutes which is INCORRECT. The default value is indefinite i.e 0. There seems to be an underlying issue with Nodejs sdk when talking from Ottoman. Our developers are looking into it. For now set the value to your desired value.

bwgjoseph commented 3 years ago

So I also did a test to set in the value, but it isn't reflected correctly as well.

If you see my initial post, it set it to 10000 and the document still shows 0 in couchbase

AV25242 commented 3 years ago

Yeah probably all related.

bwgjoseph commented 3 years ago

@AV25242 I tested with beta.2, passed in maxExpiry to 10000 but the document created is still 0

image

How do I use this TTL feature?

AV25242 commented 3 years ago

Yeah you are using it the right way, not sure why the value is not honored. Team is looking into it

AV25242 commented 3 years ago

hi @bwgjoseph I dont see any issues with Beta-2.0

I created a ttlCheck Collection (new) and as you see in the screenshot below the collection is created with a TTL of 1000 if you are using an existing collection then you will have to drop it and re-create.

Note maxExpiry setting cannot be updated on a collection.

Screen Shot 2021-06-29 at 4 37 41 PM

Next I programmatically created a document

Screen Shot 2021-06-29 at 4 38 00 PM

And then checked the Expiry on it and I did see an expiration set thats other than 0 like you were seeing.

Screen Shot 2021-06-29 at 4 38 13 PM

What I suspect is that most likely you were attempting to add the maxExpiry to a collection that you already created and were expecting the TTL to be set.

Oh btw the value is in SECOND. The documentation will be updated with the next release to mention that :)

bwgjoseph commented 3 years ago

I think you're right. I tested with a new collection, and it seems to be working fine.

Is there any way to set the expiry per document instead of per collection? I do have some use-case for it

I mean whatever that is defined in the ModelOptions could be the default expiry for all documents in that collection but if one of my documents has a different expiry than what was declared in the ModelOptions then during the document creation, maybe it could allow me to specify the expiry? Possible?

AV25242 commented 3 years ago

Can you create a new ticket and close this one. This one suffice the needs of TTL for all documents, the ask is at at an operation level.

bwgjoseph commented 3 years ago

Sure!