gpt4 book ai didi

couchdb - 无法从 PouchDB 检索值

转载 作者:行者123 更新时间:2023-12-04 23:06:48 28 4
gpt4 key购买 nike

使用 PouchDB 插入数据后,我尝试了 db.getAll()检索所有文档和 db.get()对于单个文档,但没有返回的对象包含我插入的值。

我究竟做错了什么?

new Pouch('idb://test', function(err, db) {
doc = {
test : 'foo',
value : 'bar'
}

db.post(doc, function(err, data) {
if (err) console.error(err)
else console.log(data)
})

db.allDocs(function(err, data) {
if (err) console.error(err)
else console.log(data)
})
})

最佳答案

在您完成将数据插入 PouchDB 之前,您的 allDocs 查询正在运行,由于 IndexedDB API,所有数据库查询都是异步的(它们可能必须是异步的,因为它也是一个 HTTP 客户端)。

new Pouch('idb://test', function(err, db) {
var doc = {
test : 'foo',
value : 'bar'
};
db.post(doc, function(err, data){
if (err) {
return console.error(err);
}
db.allDocs(function(err, data){
if (err) console.err(err)
else console.log(data)
});
});
});

... 应该管用。

关于couchdb - 无法从 PouchDB 检索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10299875/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com