【问题标题】:How do I use the “OR” operator in typeorm with mongodb如何在 mongodb 中使用 typeorm 中的“OR”运算符
【发布时间】:2019-07-14 10:56:27
【问题描述】:

我尝试过使用

userRepository.find({
  where: [
    {
      email: 'giberish@gmail.com',
    },
    {
      username: 'thisismyusername',
    },
  ]
});

就像 typeorm 文档中解释的那样,但我得到了这个错误:

  errmsg:
   'Error getting filter : Error getting filter BSON field from doc = [{find user} {filter [[{email giberish@gmail.com}] [{username thisismyusername}]]} {returnKey false} {showRecordId false} {$clusterTime [{clusterTime 6660127540193001473} {signature [{hash [184 253 193 112 111 39 205 239 38 92 178 205 149 85 131 136 252 114 180 30]} {keyId 6637077103550398465}]}]}] : not bson []interface {} [[{email craftball@gmail.com}] [{username thisismyusername}]]\n\tat erh/mongonet/bsonutil.go:122\n\tat 10gen/atlasproxy/bson_util.go:32\n\tat 10gen/atlasproxy/commands_security.go:521\n\tat 10gen/atlasproxy/commands.go:653\n\tat 10gen/atlasproxy/commands.go:563\n\tat 10gen/atlasproxy/session_proxy.go:256\n\tat 10gen/atlasproxy/session_proxy.go:702\n\tat 10gen/atlasproxy/session_proxy.go:526\n\tat erh/mongonet/proxy.go:209\n\tat erh/mongonet/proxy.go:104\n\tat erh/mongonet/session.go:82\n\tat src/runtime/asm_amd64.s:2361',
code: 8000,
codeName: 'AtlasError',
name: 'MongoError'

【问题讨论】:

    标签: node.js mongodb typescript nestjs typeorm


    【解决方案1】:

    我认为您的示例仅适用于 SQL 数据库。对于 mongo,您需要在 where 条件中添加运算符 $or$and

    userRepository.find({
      where: {
        $or: [
          {
            email: 'giberish@gmail.com',
          },
          {
            username: 'thisismyusername',
          },
        ]
      }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-10
      • 1970-01-01
      • 1970-01-01
      • 2018-11-11
      • 1970-01-01
      • 2023-03-15
      • 2022-01-02
      • 2015-07-08
      相关资源
      最近更新 更多