deepstream.io-storage-rethinkdb
deepstream.io-storage-rethinkdb copied to clipboard
Multiple Records Inserted in DB
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
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);
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

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 now the list (markups) gets populated but calling record.set (newMarkup.set( { airline: 'British Airways', airlineCode: 'BA', ....) no longer gets inserted into the database
Can you show me your code so I can take a look? Thanks!
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
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
Any progress?
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 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.