cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

check if stream entry exist while inserting for the 2nd time

Highlighted
Newbie

check if stream entry exist while inserting for the 2nd time

Hi,

I'm adding stream entries using this snippet:

​var params = {

  sourceType: undefined /* STRING */,

  values: values /* INFOTABLE*/,

  location: undefined /* LOCATION */,

  source: undefined /* STRING */,

timestamp: myDate /* DATETIME */,

  tags: undefined /* TAGS */

};

me.AddStreamEntry(params);

If I try to add the same row twice:

me.AddStreamEntry(params);

me.AddStreamEntry(params);


It will not add the 2nd time - OK!


I just want to know if this row already exist, I tried to add try and catch but there is no exception thrown.

What is the BEST way to do that instead of checking with getStreamEntry as this will require to check for every entry that I try to add.


*My key is the timestamp + another column (String) - I don't use the ms part of the time stamp, so if the entry is not exist but still have the same timestamp I will add 1 millisecond to the timestamp and insert it to the stream.


Thanks in advance.

Tags (2)
7 REPLIES 7

Re: check if stream entry exist while inserting for the 2nd time

Hi Assaf,

If you are on Neo4j it will create two entries for the same timestamp, if you do it with any other Backend database storage it will upsert.

If you want to prevent a new entry to overwrite an existing one, you will have to check before inserting it, but take care as if you do it too fast maybe the first entry it's still not persisted ( as AddStreamEntry it's an Async operation ).

Best Regards,

Carles.

Re: check if stream entry exist while inserting for the 2nd time

I'm using postgres and it added only 1 row

Re: check if stream entry exist while inserting for the 2nd time

Then second write it's the one that will be persisted.

Re: check if stream entry exist while inserting for the 2nd time

Not good.

I hoped that there is add AND addorupdate

Is there any smart way to do that or just to check before every insert?

Re: check if stream entry exist while inserting for the 2nd time

check before, as I where until last week on Neo4J it had to check before insert almost always to prevent duplicates.

Re: check if stream entry exist while inserting for the 2nd time

"as I where until last week"

What change did you make to stop doing this check?

Re: check if stream entry exist while inserting for the 2nd time

I was on Neo4j, then to prevent duplicates I had to check always if the entry exists, now only when it's really needed.