JavaScript storage bulk insert problem

After spending a few hours exploring JsStore and experimenting with the getting started tutorial, I decided to work with the "tutors" database provided on the site. My goal was to insert some data into the database.

var Value = [{TeacherName: "MR. BAUER", Description: "Lane's Teacher"}, {TeacherName: "MRS. BAUMAN", Description: "Lane's Aide"}, {TeacherName: "MRS. STEWART", Description: "Annabelle's Teacher"}, {TeacherName: "MR. GARLAND", Description: "Alex's Teacher"}];

Connection.insert({
Into: "Teachers",
Values: Value,
OnSuccess:function (rowsAffected){
if (rowsAffected > 0)
{
alert('Successfully Added');
}
},
OnError:function (error) {
alert(error.value);
}
});

The insertion process went smoothly. Encouraged by this success, I proceeded to explore the 'bulkInsert' feature, which seemed straightforward based on the documentation.

However, upon clearing the cache and refreshing the page, I encountered the following error:

DOMException: Failed to execute 'add' on 'IDBObjectStore': Evaluating the object store's key path did not yield a value.

I couldn't pinpoint any issues in my code despite making the necessary switch from 'insert' to 'bulkInsert'. Is there an additional step involved in using the bulkInsert method that isn't mentioned in the official documentation?

For a visual demonstration of the issue, you can watch this video sample: https://youtu.be/d-Jxx54c3dw

Answer №1

Upon reviewing your video, it appears that the key path is TeacherId; however, none of the objects in your Values array contain this property. This may be causing the issue you are experiencing. Alternatively, autoIncrement may have been mistakenly disabled. I recommend checking out the Structuring the Database section for further guidance.

Answer №2

According to the documentation for jsstore () -

Using bulk insert is significantly faster than using the insert api as it bypasses checks and returns nothing.

This means that certain column options like auto increment and default values will not be applied. It also does not guarantee that all data has been successfully inserted.

The error message you are encountering indicates that a value for the primary key has not been provided. This is because AutoIncrement is specified for the primary key, but this feature is not calculated when using bulkInsert.

You may be wondering why one would choose to use bulk Insert.

The purpose of bulk insert is to quickly insert a large amount of data at once.

For example, if you have thousands of records in a server, excel sheet, or JSON file that you want to rapidly insert into indexeddb without checking or modifying the data.

I hope this explanation addresses your concerns.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exclude the data key from form submission based on condition in React

Is it possible to omit the onSubmit value if a checkbox is selected, without requiring a specific label/input? For example, when the indefinite runTime box is checked, the key runTimeSeconds doesn't need to be included in the payload. Can this logic b ...

Parsing JSON data received from Angular using JSP

As I navigate through my Angular application, I'm encountering a challenge when trying to save data on the server side using JSP. The issue arises when Angular's $save method sends the object data in a JSON format that is not familiar to me. This ...

Invoke PHP by clicking on a button

I am facing an issue with a button I have created. Here is the code for it: <input type="submit" name="kudos_button" value="★ Give kudos"/>' To test it, I wrote a PHP script like this below the </html> tag: ...

What is the best way to use element.appendChild to generate a link?

I am currently utilizing the following snippet of Javascript to extract information from the current webpage using a browser extension. I have only included a portion of the code that is relevant, as the full script is quite lengthy. The code works perfect ...

What is the best method in Django to dynamically load JavaScript based on the view name, if it exists?

In the realm of Django, I find myself faced with the challenge of loading a JavaScript file that matches the name of the view whenever I call said view with a template. For example, if I invoke the view foo, my goal is to automatically load foo.js from a ...

What is the method for adding two elements to an array?

Currently, I am using JavaScript to push elements into an array. As a result, the output looks like this: ["api", "management", "provision", "tenant", "external", "provider"] => Correct Now, after pushing data into the array, I want to append two el ...

Generating a highchart visualizing a pie chart using data from a local JSON file (OBJECT)

This is the JSON data from my JSON file {"diskspace":100,"diskspace.free":50,"time":8,"time.played":2,"controllers":25,"controllers.used":3, "controllers.new":10, "controllers.broken":12} I want to represent this JSON data in various forms of pie cha ...

Does anyone know of a JavaScript function that works similarly to clientX and clientY but for tooltips when the mouse moves?

When using plain JavaScript to create a function that moves a tooltip on mouse move, the function works the first time with clientX and clientY, but fails to work when repeated. What could be causing this issue with clientX and clientY? Any suggestions on ...

Stay updated with the complex query change feed in RethinkDB

When faced with a query like the following: r.db('universe') .table('Star') .getAll( r.db('universe').table('Ship').get(idShip)('idCurrentGalaxy'), {index: 'idGalaxy'} ) .changes ...

How can TypeScript leverage the power of JavaScript libraries?

As a newcomer to TypeScript, I apologize if this question seems simplistic. My goal is to incorporate JavaScript libraries into a .ts file while utilizing node.js for running my program via the console. In my previous experience with JavaScript, I utilize ...

Unable to eliminate UI component by clicking in Angular

I have been experimenting with different examples and attempted a few methods, but I am struggling to remove items from the UI level. I attempted to use the *ngFor directive, however, it seems to only remove <span> elements and not the <button> ...

An issue occurred while attempting to utilize fs.readFileSync

Attempting to change an uploaded image to base 64 format var file = e.target.files[0]; var imageFile = fs.readFileSync(file); var encoded = new Buffer(imageFile).toString('base64'); An error is encountered: TypeError: __W ...

What is the reason behind having to refresh my ReactJS page despite it being built with ReactJS?

I have developed a task management application where users can input notes that should automatically update the list below. However, I am facing an issue where the main home page does not display the updated todos from the database unless I manually refres ...

What steps do I need to take to transform this click event function into one that is triggered automatically upon the div loading?

In order to automatically load content into a div using innerHTML, the PHP file must be retrieved and the div updated with its content. Within this div is another one labeled "tweet" which displays actual tweets based on a specific hashtag provided through ...

What is the best way to incorporate a variable in the find() method to search for similar matches?

I've been working on a dictionary web application and now I'm in the process of developing a search engine. My goal is to allow users to enter part of a word and receive all similar matches. For instance, if they type "ava", they should get back ...

Guide on including the angular value (id) in conjunction with repeating data-target for executing a function

I have the following code snippet. Now, I am trying to pass a dynamic AngularJS variable, specifically the id of a repeating list. The button in question is used for deactivation purposes, and upon clicking it, a confirmation box pops up. Upon confirming ...

Customize the toggle icon for the accordion in Framework7

I took inspiration from the custom accordion elements provided in the documentation and made some alterations to the icons. However, I'm facing an issue with getting the toggle functionality of the icons to work properly. My goal is to have a "+" dis ...

Utilize a date state variable in JSX Text based on a specific condition

My goal is to create a feature that allows users to pick a date using DateTimePickerModal. I want to display a clickable message that says "Select date" before any date is chosen, and then replace it with the selected date. While I am not certain if there ...

Prevent jQuery from scrolling once the fixed image reaches the bottom of the page

I am struggling to figure out how to keep an image fixed at the top of the footer div while scrolling to the bottom of a webpage. My approach involved calculating the height of the footer in order to adjust the scrolling behavior by subtracting it from th ...

In Firefox mobile, a fixed positioned element will move with the page until the scrolling comes to a halt

I am facing an issue with a CSS element set to position: fixed. While it works perfectly on desktop browsers, it behaves poorly on mobile browsers, especially Firefox. The main problem is that the fixed element scrolls along with the page and then abrupt ...