admin管理员组文章数量:1024615
I have created a IndexedDB setup in my ReactJs PWA.
The following error is thrown:
NotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found.
at line userSearchDBtx = userSearchDB.transaction("userdata","readwrite")
My function looks like this:
function Users() {
let userSearchDB,userSearchDBstore,userSearchDBtx;
let userDbrequest = window.indexedDB.open("MyTestDatabase", 1);
useEffect(()=>{
if (!window.indexedDB) {
console.log("Your browser doesn't support a stable version of IndexedDB. Such and such feature will not be available.");
}
else console.log("IndexedDB supported")
userDbrequest.onupgradeneeded = function(event) {
userSearchDB = event.target.result;
userSearchDBtx = event.target.transaction;
userSearchDBstore = userSearchDB.createObjectStore("userdata",{keyPath:"uid"})
};
userDbrequest.onerror = function(event) {
console.log("ERROR: " + event.target.errorCode)
};
userDbrequest.onsuccess = function(event) {
console.log("IndexdDb Working")
userSearchDB = event.target.result
userSearchDBtx = userSearchDB.transaction("userdata","readwrite");
userSearchDBstore = userSearchDBtx.objectStore("userdata");
};
//Here also put is unknown
userSearchDBstore.put({uid:3854238974,phone:3257777,name:"shan",email:"[email protected]"})
},[])
}
I have created a IndexedDB setup in my ReactJs PWA.
The following error is thrown:
NotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found.
at line userSearchDBtx = userSearchDB.transaction("userdata","readwrite")
My function looks like this:
function Users() {
let userSearchDB,userSearchDBstore,userSearchDBtx;
let userDbrequest = window.indexedDB.open("MyTestDatabase", 1);
useEffect(()=>{
if (!window.indexedDB) {
console.log("Your browser doesn't support a stable version of IndexedDB. Such and such feature will not be available.");
}
else console.log("IndexedDB supported")
userDbrequest.onupgradeneeded = function(event) {
userSearchDB = event.target.result;
userSearchDBtx = event.target.transaction;
userSearchDBstore = userSearchDB.createObjectStore("userdata",{keyPath:"uid"})
};
userDbrequest.onerror = function(event) {
console.log("ERROR: " + event.target.errorCode)
};
userDbrequest.onsuccess = function(event) {
console.log("IndexdDb Working")
userSearchDB = event.target.result
userSearchDBtx = userSearchDB.transaction("userdata","readwrite");
userSearchDBstore = userSearchDBtx.objectStore("userdata");
};
//Here also put is unknown
userSearchDBstore.put({uid:3854238974,phone:3257777,name:"shan",email:"[email protected]"})
},[])
}
Share
Improve this question
edited Oct 1, 2020 at 9:25
Paul T. Rawkeen
4,1143 gold badges36 silver badges52 bronze badges
asked Oct 1, 2020 at 8:09
ShantanuShantanu
311 gold badge1 silver badge7 bronze badges
4 Answers
Reset to default 0let userDbrequest = window.indexedDB.open("MyTestDatabase", 1);
Place this line in useEffect()
The code should be
let userSearchDB,userSearchDBstore,userSearchDBtx,userDbrequest;
useEffect(()=>{
userDbrequest = window.indexedDB.open("MyTestDatabase", 2);
...Conrinue your code
},[])
Also, Increment the version while doing so
You are calling userSearchDBstore.put(...)
before the db connected, which means no guarantee upgrade needed callback pleted, which means no guarantee store created.
You need to wait. Move the put call to within the open db request success callback so that it only runs once database is upgraded.
I found out the cause was the wrong storeNames at: const request = db .transaction(storeNames , "readwrite")
This happened for me because I was on localhost:3000
. Try visiting $ip:3000
in your browser.
You can inspect your database endpoint in Chrome with Inspect -> Application -> Storage -> IndexedDB.
I have created a IndexedDB setup in my ReactJs PWA.
The following error is thrown:
NotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found.
at line userSearchDBtx = userSearchDB.transaction("userdata","readwrite")
My function looks like this:
function Users() {
let userSearchDB,userSearchDBstore,userSearchDBtx;
let userDbrequest = window.indexedDB.open("MyTestDatabase", 1);
useEffect(()=>{
if (!window.indexedDB) {
console.log("Your browser doesn't support a stable version of IndexedDB. Such and such feature will not be available.");
}
else console.log("IndexedDB supported")
userDbrequest.onupgradeneeded = function(event) {
userSearchDB = event.target.result;
userSearchDBtx = event.target.transaction;
userSearchDBstore = userSearchDB.createObjectStore("userdata",{keyPath:"uid"})
};
userDbrequest.onerror = function(event) {
console.log("ERROR: " + event.target.errorCode)
};
userDbrequest.onsuccess = function(event) {
console.log("IndexdDb Working")
userSearchDB = event.target.result
userSearchDBtx = userSearchDB.transaction("userdata","readwrite");
userSearchDBstore = userSearchDBtx.objectStore("userdata");
};
//Here also put is unknown
userSearchDBstore.put({uid:3854238974,phone:3257777,name:"shan",email:"[email protected]"})
},[])
}
I have created a IndexedDB setup in my ReactJs PWA.
The following error is thrown:
NotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found.
at line userSearchDBtx = userSearchDB.transaction("userdata","readwrite")
My function looks like this:
function Users() {
let userSearchDB,userSearchDBstore,userSearchDBtx;
let userDbrequest = window.indexedDB.open("MyTestDatabase", 1);
useEffect(()=>{
if (!window.indexedDB) {
console.log("Your browser doesn't support a stable version of IndexedDB. Such and such feature will not be available.");
}
else console.log("IndexedDB supported")
userDbrequest.onupgradeneeded = function(event) {
userSearchDB = event.target.result;
userSearchDBtx = event.target.transaction;
userSearchDBstore = userSearchDB.createObjectStore("userdata",{keyPath:"uid"})
};
userDbrequest.onerror = function(event) {
console.log("ERROR: " + event.target.errorCode)
};
userDbrequest.onsuccess = function(event) {
console.log("IndexdDb Working")
userSearchDB = event.target.result
userSearchDBtx = userSearchDB.transaction("userdata","readwrite");
userSearchDBstore = userSearchDBtx.objectStore("userdata");
};
//Here also put is unknown
userSearchDBstore.put({uid:3854238974,phone:3257777,name:"shan",email:"[email protected]"})
},[])
}
Share
Improve this question
edited Oct 1, 2020 at 9:25
Paul T. Rawkeen
4,1143 gold badges36 silver badges52 bronze badges
asked Oct 1, 2020 at 8:09
ShantanuShantanu
311 gold badge1 silver badge7 bronze badges
4 Answers
Reset to default 0let userDbrequest = window.indexedDB.open("MyTestDatabase", 1);
Place this line in useEffect()
The code should be
let userSearchDB,userSearchDBstore,userSearchDBtx,userDbrequest;
useEffect(()=>{
userDbrequest = window.indexedDB.open("MyTestDatabase", 2);
...Conrinue your code
},[])
Also, Increment the version while doing so
You are calling userSearchDBstore.put(...)
before the db connected, which means no guarantee upgrade needed callback pleted, which means no guarantee store created.
You need to wait. Move the put call to within the open db request success callback so that it only runs once database is upgraded.
I found out the cause was the wrong storeNames at: const request = db .transaction(storeNames , "readwrite")
This happened for me because I was on localhost:3000
. Try visiting $ip:3000
in your browser.
You can inspect your database endpoint in Chrome with Inspect -> Application -> Storage -> IndexedDB.
本文标签:
版权声明:本文标题:javascript - IndexedDB Error : NotFoundError : Failed to execute 'transaction' on 'IDBDatabase': 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745590026a2157832.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论