Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Records Inserted in DB #16

Open
joshua1 opened this issue Dec 6, 2016 · 10 comments
Open

Multiple Records Inserted in DB #16

joshua1 opened this issue Dec 6, 2016 · 10 comments

Comments

@joshua1
Copy link

joshua1 commented Dec 6, 2016

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

@yasserf
Copy link
Contributor

yasserf commented Dec 6, 2016

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);

@joshua1
Copy link
Author

joshua1 commented Dec 7, 2016

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

@yasserf
Copy link
Contributor

yasserf commented Dec 7, 2016

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.

@joshua1
Copy link
Author

joshua1 commented Dec 7, 2016

@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

@yasserf
Copy link
Contributor

yasserf commented Dec 7, 2016

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

@rielmedia
Copy link

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

@yasserf
Copy link
Contributor

yasserf commented Mar 16, 2017

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

@franz-josef-kaiser
Copy link

Any progress?

@rielmedia
Copy link

rielmedia commented Jun 12, 2017 via email

@yasserf
Copy link
Contributor

yasserf commented Jun 13, 2017

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants