PouchDB find 方法不返回文档
在复制的同时,我运行查找查询。但是当第一次加载页面时,该方法返回 0 个文档。如果您在大约 5 秒后重新加载页面,该方法将返回所有文档
public createIndex = async (): Promise<unknown> => {
try {
return await this.database.createIndex({
index: {
fields: ['title']
}
});
} catch (e) {
ErrorHandler.processError(e);
return null;
}
};
public find = async (
userId: string,
): Promise<any> => {
try {
return await this.database.find({
selector: {
$or: [
{author: userId},
{writers: {$regex: userId}},
{readers: {$regex: userId}},
],
$and: [
{title: {$gt: null}}
],
$not: [
{_delete: true}
],
},
sort: [{title: "asc"}],
fields: ["_id", "_rev", "id", "title", "created", "modified", "sharedUI", "author", "writers", "readers", "preview"],
})
} catch (e) {
ErrorHandler.processError(e);
return null;
}
};
React.useEffect(() => {
const storage = new Database('schemes', {username: 'username', password: 'username'});
storage.createIndex().then(() => {
storage.find(userId).then((resFind) => {
console.log('resFind', resFind)
})
})
}, [userId]);
in parallel with replication, I run the find query. But when the page is loaded for the first time, the method returns 0 documents. if you reload the page after about 5 seconds, the method returns all the documents
public createIndex = async (): Promise<unknown> => {
try {
return await this.database.createIndex({
index: {
fields: ['title']
}
});
} catch (e) {
ErrorHandler.processError(e);
return null;
}
};
public find = async (
userId: string,
): Promise<any> => {
try {
return await this.database.find({
selector: {
$or: [
{author: userId},
{writers: {$regex: userId}},
{readers: {$regex: userId}},
],
$and: [
{title: {$gt: null}}
],
$not: [
{_delete: true}
],
},
sort: [{title: "asc"}],
fields: ["_id", "_rev", "id", "title", "created", "modified", "sharedUI", "author", "writers", "readers", "preview"],
})
} catch (e) {
ErrorHandler.processError(e);
return null;
}
};
React.useEffect(() => {
const storage = new Database('schemes', {username: 'username', password: 'username'});
storage.createIndex().then(() => {
storage.find(userId).then((resFind) => {
console.log('resFind', resFind)
})
})
}, [userId]);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论