RavenDB v4 - Node.js Client - Expiration

82 views
Skip to first unread message

Troy

unread,
Oct 21, 2017, 1:33:09 AM10/21/17
to RavenDB - 2nd generation document database
How can you set a collection to expire documents or when using the node.js client set an expiration time? I would like a collection to expire all documents if possible, but I don't see a way to set that in the v4 Studio...

Thanks.

Oren Eini (Ayende Rahien)

unread,
Oct 22, 2017, 2:11:19 AM10/22/17
to ravendb
Expiration is set on a per document basis. 
This is done by putting a metadata value of `@expires': ISO8601Date in the metadata.

This is done something like this:


var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate()+1);

await session.store(
{
content: content,
createdAt: new Date(),
isChecked: false, "@metadata": { "@expires": tomorrow .toISOString() }
}
, null, "TodoItems");

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


On Sat, Oct 21, 2017 at 8:33 AM, Troy <tza...@gmail.com> wrote:
How can you set a collection to expire documents or when using the node.js client set an expiration time? I would like a collection to expire all documents if possible, but I don't see a way to set that in the v4 Studio...

Thanks.

--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Troy

unread,
Oct 22, 2017, 2:53:16 AM10/22/17
to RavenDB - 2nd generation document database
Thank Oren,

It doesn't appear to be working, nor does it appears the node client is actually adding the document @metadata other than the default metadata see what I see in Studio:

"@metadata": {
        "@collection": "Sessions",
        "Raven-Node-Type": "Sessions"
    }

even though store document with this:

 '@metadata': {
      '@expires': futureDate.toISOString(),
    },

I would have expected to see:

"@metadata": {
        "@collection": "Sessions",
        "@expires": "2017-10-22T06:37:20.145Z",
        "Raven-Node-Type": "Sessions"
    }

Is there anything you have to do to make sure that the database, or server, is actually looking for expiring documents? When I add the @expires to the document, that is not honored either...
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Oct 22, 2017, 3:04:59 AM10/22/17
to ravendb
Expiration runs every minute or so, IIRC.
Can you send the code that you are using so we can look at this?
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Troy

unread,
Oct 22, 2017, 10:28:00 AM10/22/17
to RavenDB - 2nd generation document database
import DocumentStore from 'ravendb';

const config = {
  ravendb: {
    database: 'node-app',
  },
};

const store = DocumentStore.create(config.ravendb.url, config.ravendb.database);
store.initialize();

const expiresAt = new Date(new Date().getTime() + (1 * 60000));
async function seed() {
  const session = store.openSession();
  await session.store({
    firstName: 'Delete',
    lastName: 'Me',
    email: 'dele...@test.com',
    password: 'TestPassword',
    seeIsoFormatTemp: expiresAt.toISOString(),
    '@metadata': {
      '@expires': expiresAt.toISOString(),
    },
  }, null, 'TestExpirationDocument');

  await session.saveChanges();
}

seed();


export default store;

Oren Eini (Ayende Rahien)

unread,
Oct 23, 2017, 2:15:18 AM10/23/17
to ravendb
Thanks, looking into this. I think that this is probably just fixed.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Oct 23, 2017, 2:46:56 AM10/23/17
to ravendb
Figure it out, there is an mismatch in the date handling, we don't have the JS value dates handled properly (missing 4 zeroes at the end).
We'll fix that today

Fitzchak Yitzchaki

unread,
Oct 23, 2017, 3:26:31 AM10/23/17
to <ravendb@googlegroups.com>

Best Regards,

Hibernating Rhinos Ltd  cid:image001.png@01CF95E2.8ED1B7D0

Fitzchak Yitzchaki l Senior Software Engineer Mobile:+972-58-345-9538

Troy

unread,
Oct 23, 2017, 10:42:05 AM10/23/17
to RavenDB - 2nd generation document database
Great, when will the nightly Docker be available? I am using the docker version and would love to get the fix via the Docker version.

Grzegorz Lachowski

unread,
Oct 24, 2017, 2:36:47 AM10/24/17
to RavenDB - 2nd generation document database

Troy

unread,
Oct 24, 2017, 10:17:20 AM10/24/17
to RavenDB - 2nd generation document database
Perfect! Thank you.

Should the latest nightly have the Expiration fix in it?

Running:
Server: 4.0.0-nightly-20171024-0909
Studio: 4.0.0-nightly-20171024-0909

And it seems to not be resolved.

Oren Eini (Ayende Rahien)

unread,
Oct 24, 2017, 3:19:44 PM10/24/17
to ravendb
You also need to enable the expiration itself.
Inline image 1
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Marcelo Volmaro

unread,
Oct 24, 2017, 7:02:12 PM10/24/17
to RavenDB - 2nd generation document database
That seems not to be implemented in the public version of studio (as 4.0.0-nightly-20171024-0909 at least...) I'm waiting for that setting to be present in the UI since the first beta...

Troy

unread,
Oct 24, 2017, 10:16:02 PM10/24/17
to RavenDB - 2nd generation document database
I don't see that... I see this in the Studio:


Troy

unread,
Oct 24, 2017, 10:21:27 PM10/24/17
to RavenDB - 2nd generation document database
I realized I was not using the latest nightly as I spin the RC1 docker file... once I updated, I do see the Document Expiration using Server: 4.0.0-nightly-20171024-0909

Thanks Oren and Team!

On Tuesday, October 24, 2017 at 3:19:44 PM UTC-4, Oren Eini wrote:

Troy

unread,
Oct 24, 2017, 10:42:19 PM10/24/17
to RavenDB - 2nd generation document database
Confirmed it works if I manually add the @expires metedata ... the NPM version of the node client has not been updated to actually add the @expires property even though I am setting it. Or the JS data format without the 0000 is still and issue?


On Tuesday, October 24, 2017 at 3:19:44 PM UTC-4, Oren Eini wrote:

Oren Eini (Ayende Rahien)

unread,
Oct 25, 2017, 1:18:29 AM10/25/17
to ravendb
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Marcelo Volmaro

unread,
Oct 25, 2017, 7:22:30 AM10/25/17
to RavenDB - 2nd generation document database
Oren, I still don't see the expiration settings in studio. And I just downloaded the latest version just to be sure (Studio: 4.0.0-nightly-20170922-1004, Server 4.0.0-nightly-20171025-0705).
Tried deleting all the dbs, and also deleting both System/Databases folders and letting Raven create new ones... 

Opening the debugger in Chrome shows that studio throws an error (nor sure if it's related)
TypeError: Cannot read property 'database' of null
    at
Function.e.forCurrentPage (http://localhost:8080/studio/App/main.js:3:20734)
    at e
.navigateToResourceSpecificPage (http://localhost:8080/studio/App/main.js:19:23122)
    at
Object.<anonymous> (http://localhost:8080/studio/App/main.js:19:22910)
    at u
(http://localhost:8080/studio/App/external-libs.js:3:25419)
    at
Object.fireWith [as resolveWith] (http://localhost:8080/studio/App/external-libs.js:3:26187)
    at
Object.i.(anonymous function) [as resolve] (http://localhost:8080/studio/App/external-libs.js:3:27176)
    at t
.e.onOpen (http://localhost:8080/studio/App/main.js:10:177)
    at t
.onOpen (http://localhost:8080/studio/App/main.js:17:4409)
    at
WebSocket.webSocket.onopen (http://localhost:8080/studio/App/main.js:10:3)



mar...@ayende.com

unread,
Oct 25, 2017, 7:42:54 AM10/25/17
to RavenDB - 2nd generation document database
Hi,

Studio and server versions should match. Please make sure Raven.Studio.zip was updated during server update. 

Alternately please clear your browser cache. 

Best regards,
Marcin 

Marcelo Volmaro

unread,
Oct 25, 2017, 7:48:18 AM10/25/17
to RavenDB - 2nd generation document database
Yes, thanks. It was the browser cache. What's strange is that I forced a refresh (was the first thing I though), but still have the old version of studio. Only after I opened chrome's inspector and checked the "disable cache" option, the refresh actually worked...
Are you using a too aggressive caching? Maybe service workers? I never had to do that (open the inspector) to force a refresh, and that could be an issue if you update studio too often...

Marcelo Volmaro

unread,
Oct 25, 2017, 8:34:28 AM10/25/17
to RavenDB - 2nd generation document database
BTW: Since you already know that there is a version mismatch between studio/server, you can warn the user about that and ask him to force refresh the browser...

Oren Eini (Ayende Rahien)

unread,
Oct 25, 2017, 8:36:17 AM10/25/17
to ravendb
That is a good idea, or maybe server the urls from the server version, to avoid it completely?

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


Reply all
Reply to author
Forward
0 new messages