PouchDB find 方法不返回文档

发布于 2025-01-14 14:58:22 字数 1346 浏览 0 评论 0原文

在复制的同时,我运行查找查询。但是当第一次加载页面时,该方法返回 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文