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]);