deepstream.io-storage-rethinkdb icon indicating copy to clipboard operation
deepstream.io-storage-rethinkdb copied to clipboard

Multiple Records Inserted in DB

Open joshua1 opened this issue 8 years ago • 10 comments
trafficstars

Hi, I tried using the code snippet below to insert data into a table in rethinkDB if those records do not exist. This runs ok, but multiple Data rows with just Id and nothing else are created alongside the data i am trying to save. a single forloop or forEach run of just 14 records produces inserts of 140 records. Please look at my code and tell me what is wrong. i am on the verge of removing the rethinkDB storage lib

  const markups = client.record.getList('Markups');
  console.log(`Number of records is ${markups.getEntries().length}`);
  console.log(markups.getEntries());
  if (markups.isEmpty()) {
    // create the record for each markup
    for (var i = 0;i < markupSeeds.length;i++) {
      const id = 'Markups/' + client.getUid();
      const toSave = new MarkupsModel(markupSeeds[i]);
      client.record.getRecord(id).set(toSave);
    }
    markups.discard();
  }

markups always returns as an empty list despite the multitude of records in the Markups Table in the DB Thanks

joshua1 avatar Dec 06 '16 08:12 joshua1

Your saving a class and not json data, could that be the problem?

const toSave = new MarkupsModel(markupSeeds[i]);
client.record.getRecord(id).set(toSave);

yasserf avatar Dec 06 '16 15:12 yasserf

Hi @yasserf That is not the cause of the issue all the records actually get inserted, there are just some extra rows inserted that do not bear any meaning . I passed in markupSeeds[0] which is just a plain JS object . A single record this time and still found double insertion one of which was the actual js Object and the other was just an empty row with Id. Please see below My modified script

const markups = client.record.getList('Markups');

  markups.whenReady(() => {
    console.log(`Number of records is ${markups.getEntries().length}`);
    console.log(markups.getEntries());
    if (markups.isEmpty()) {
      // create the record for each markup
      //  for (var i = 0;i < markupSeeds.length;i++) {
      const id = 'Markups/' + client.getUid();
      // const toSave = new MarkupsModel(markupSeeds[i])
      const newMarkup = client.record.getRecord(id);
      newMarkup.set(  {
    airline: 'British Airways',
    airlineCode: 'BA',
    dealCode: 'TIE08',
    serial: 1,
    dealOps: 'rate',
    mark: 'down',
    figure: 5,
    destination: [
      'all',
    ],
    travelClass: [
      'all',
    ],
    travelClassException: [],
    destinationException: [],
  });
      newMarkup.discard();
      //  }
      console.log('Length is now ' + markups.getEntries().length);
    }
  });
  // markups.unsubscribe()
  markups.discard();

with this i still got two rows of data inserted in rethink DB see below screen shot 2016-12-07 at 9 44 05 am

joshua1 avatar Dec 07 '16 07:12 joshua1

Ah! My bad sorry.

Your missing 'markups.addEntry(id)' that adds the record into the list. Currently lists need to maintained manually, something that will change once we implement collections which does auto grouping of records.

yasserf avatar Dec 07 '16 08:12 yasserf

@yasserf now the list (markups) gets populated but calling record.set (newMarkup.set( { airline: 'British Airways', airlineCode: 'BA', ....) no longer gets inserted into the database

joshua1 avatar Dec 07 '16 10:12 joshua1

Can you show me your code so I can take a look? Thanks!

yasserf avatar Dec 07 '16 15:12 yasserf

Hi @joshua1 and @yasserf. I am having the same issue. For every record I set, there is an additional empty record being set in my RethinkDB instance. I am using Deepstream with RethinkDB in a React app on an AWS server.

Has this issue been resolved? Is there a fix or workaround for this yet? I have an app that needs to be completed in about 2.5 weeks and am anxious to solve this problem.

Thanks

rielmedia avatar Mar 15 '17 03:03 rielmedia

Hey,

I'm not aware of a fix for this. I'll look into it on weekend and ideally get to the bottom of it then.

Thanks

yasserf avatar Mar 16 '17 11:03 yasserf

Any progress?

franz-josef-kaiser avatar Jun 12 '17 21:06 franz-josef-kaiser

No. Unfortenately we decide to switch to a different technology. We were attempting to meet a deadline and could not afford to spend anymore time troubleshooting the issue.

On Mon, Jun 12, 2017 at 5:13 PM, Franz Josef Kaiser < [email protected]> wrote:

Any progress?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/deepstreamIO/deepstream.io-storage-rethinkdb/issues/16#issuecomment-307930827, or mute the thread https://github.com/notifications/unsubscribe-auth/ACJzkVTpcL3B8j0dzAjSDRUBlCXZUqdcks5sDanlgaJpZM4LFILJ .

-- Karl Sturdivant II Designer & Digital Developer

Riel Media, LLC. p: 614.390.6299 e: [email protected] http://www.jointherevolutions.com/

rielmedia avatar Jun 12 '17 22:06 rielmedia

@rielmedia I'm sorry to hear that, apologies for not getting back sooner.

I think the problem is around creating and setting the data together.

One solution is to use the setData API which was just introduced to bypass this, or we send the set once the record is ready and not pipeline them in the client.

yasserf avatar Jun 13 '17 08:06 yasserf