首页 > 解决方案 > 过滤器包括数据、Loopback、Mongodb、NodeJs

问题描述

created: "2021-07-19T07:20:28.742Z"
entity: "User"
entityId: "60f527bc517a22003f174ba1"
id: "60f527bc517a22003f174ba3"
user: {readOnly: {balance: 0, plan: "monthly", balanceExpireAt: "2021-08- 
02T07:20:28.730Z",…},…}

filter: {
  order: 'created DESC',
  where: {
    'user': {
       exists: true // does not work!! 
    }
  }, // or 'user': { 'orders': {gt: []} } also does not work (
  include: {
    relation: 'user',
    scope: {
      fields: ['email', 'id', 'readOnly'],
      include: {
        relation: 'orders',
        scope: {
          fields: ['id', 'info', 'settings'],
          where: {
            'or': [
               {'notifications.telegram.enabled': true},
                  ],
                },
              },
            },
          },
        },
        limit: this.limit,
        skip: this.skip,
      },

user是我的查询中的嵌套数据,我无法以任何方式按用户对我的查询的顶层进行排序。例如,我想获取所有有书籍的用户的记录。但无论如何我都得到了所有的记录,只有当用户有书时,我才得到用户的记录,当没有书的书时,我得到没有用户的记录。我只需要过滤有书籍的用户的存在。用户的书也是一个嵌套记录。

标签: node.jsmongodbloopback

解决方案


推荐阅读