mdn / mdn/content

"Using IndexedDB" guide seems to be out of sync with the more specific documentation

Open
#27,330 0 comments 0 reactions 0 assignees View on GitHub
area: IndexedDB Content:WebAPI
Dominant language
Markdown
Stars
11k
Forks
23.2k
Avg merge
2d 9h
Merged PRs (30d)
331

Description

### MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB

### What specific section or headline is this issue about?

Multiple, listed below

### What information was incorrect, unhelpful, or incomplete?

It seems like there are multiple things in the "Using indexedDB" guide that are inconsistent or have fallen out of sync with the more specific documentation. I have found three examples so far, but it seems possible that there are more.

First:
In the ["Structuring the database" section](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB#structuring_the_database), an example says

```
// Use transaction oncomplete to make sure the objectStore creation is
// finished before adding data into it.
```
but then the very next section demonstrates adding data to the `objectStore` without waiting for the transaction to complete, which seems wrong. If waiting for the transaction to complete before accessing the object store is necessary, all the examples that show the object store creation and data access to that object store should either show that step being done or at least have a comment calling out that that step is being skipped for simplicity.

Second:
This sentence in the ["Adding data to the database" section](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB#adding_data_to_the_database) seems inconsistent.
> You can pass an empty array if you want the transaction to span all object stores, but don't do it because the spec says an empty array should generate an InvalidAccessError.

[The documentation for the specific function](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/transaction) gives a different, (I'm guessing) more appropriate way of doing this:

> If you need to access all object stores in the database, you can use the property [`IDBDatabase.objectStoreNames`](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/objectStoreNames):
> ```
> const transaction = db.transaction(db.objectStoreNames);
> ```

It then says specifically not to do what the guide suggests potentially doing

> Passing an empty array will throw an exception.

I think that the guide should probably suggest using `IDBDatabase.objectStoreNames` rather than an empty array. If there is an appropriate time or Firefox version when an empty array ought to be passed instead, that should be stated explicitly.

Third:
The ["Adding, retrieving, and removing data" section](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB#adding_retrieving_and_removing_data) has a note discussing durability guarantees that suggests using

> the experimental (non-standard) readwriteflush mode (see [IDBDatabase.transaction](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/transaction)).

The linked docs do discuss using the `readwriteflush` mode, but also indicate that this function takes an `options` argument that can be used to set `durability: "strict"`. It is never mentioned if there is any difference between using `readwriteflush` and `durability: "strict"` (perhaps this should be mentioned), but the `options` object sounds much more standardized and therefore probably preferable. It seems likely that the `options` parameter was added later and that `readwriteflush` was added prior to that in order to grant access to that functionality when there was no other way to access it. But the "Browser Compatibility" section indicates that Firefox has had "Full support" for this feature since version 10.

I don't really know what changes to suggest here since I don't know the truth of the situation. If my guess above is correct, probably the "Browser Compatibility" section should be fixed, the note in "Using indexedDB" guide should mention `durability: "strict"` and probably not mention `readwriteflush` mode. And the `transaction` docs' discussion of `readwriteflush` mode should indicate that the mode should only be used for some specific range of Firefox versions and other versions should use `durability: "strict"`.

### What did you expect to see?

I'm not sure exactly what the text ought to read since I am trying to learn how this interface works from the inconsistent documentation, but I have given my best guesses in the previous section.

### Do you have any supporting links, references, or citations?

_No response_

### Do you have anything more you want to share?

_No response_

### MDN metadata

Page report details

* Folder: `en-us/web/api/indexeddb_api/using_indexeddb`
* MDN URL: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB
* GitHub URL: https://github.com/mdn/content/blob/main/files/en-us/web/api/indexeddb_api/using_indexeddb/index.md
* Last commit: https://github.com/mdn/content/commit/4b9377a26bb7094a8f13551cf328865a6457f5ee
* Document last modified: 2023-03-21T12:46:26.000Z

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.