如何在带有 mongodb 的 typeorm 中使用“或”运算符

How do I use the “OR” operator in typeorm with mongodb

我试过使用

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'

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

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