title: How to query mongodb dynamically with interface{}
body: <p>Am trying to make a dynamic mongodb query using a Go interface as shown bellow</p>
  
  <pre><code>func (m *NfInstanceDataAccess) FindIp(preferredNfInstances string, args ...interface{}) ([]model.NfProfile, bool) {
      var ip []model.NfProfile
      pipeline := bson.M{"nfType": preferredNfInstances, "allowedNssais.sst": args, "allowedNssais.sd": args}
      filter := bson.M{"ipv4Addresses": true}
      err := db.C(COLLECTION).Find(pipeline).Select(filter).All(&amp;ip)
      if err != nil {
          return ip, false
      }
      return ip, true
  }
  </code></pre>
  
  <p>There is no error when I use the function in my http server handler as </p>
  
  <pre><code>    nfInstanceIp, success := Da.FindIp(targetNfType, sst, sd)
              if !success {
                  WriteError(response, ErrInternalServer)
                  return
              }
  </code></pre>
  
  <p>but the response nfInstanceIp is always empty even though there values in my mongodb collection that matches the FindIp arguments. 
  When I use other types like integer and string as in below code, everything work.</p>
  
  <pre><code>func (m *NfInstanceDataAccess) FindIp(preferredNfInstances string, sst int, sd string) ([]model.NfProfile, bool) {
      var ip []model.NfProfile
      pipeline := bson.M{"nfType": preferredNfInstances, "allowedNssais.sst": sst, "allowedNssais.sd": sd}
      filter := bson.M{"ipv4Addresses": true}
      err := db.C(COLLECTION).Find(pipeline).Select(filter).All(&amp;ip)
      if err != nil {
          return ip, false
      }
      return ip, true
  }
  </code></pre>
  
  <p>Can anyone explain to me the reason why the use of interface is not working and how to write this function dynamically?</p>
  
  <p>Modifying the function as suggested to use mongodb $or logic like the code below</p>
  
  <pre><code>func (m *NfInstanceDataAccess) FindIp(preferredNfInstances string, args ...interface{}) ([]model.NfProfile, bool) {
      var ip []model.NfProfile
      pipeline := bson.M{
          "nfType": preferredNfInstances,
          "$or": []interface{}{
              bson.M{"sNssais.sst": args[0].(int32), "sNssais.sd": args[1].(string)},
              bson.M{"amfInfo.taiList.tac": args},
              bson.M{"smfInfo.taiList.tac": args},
              bson.M{"upfInfo.taiList.tac": args},
          },
      }
      filter := bson.M{"ipv4Addresses": true}
      err := db.C(COLLECTION).Find(pipeline).Select(filter).All(&amp;ip)
      if err != nil {
          return ip, false
      }
      return ip, true
  }
  </code></pre>
  
  <p>The logical $or does not work. Its only work when my FindIp input matches </p>
  
  <pre><code>bson.M{"sNssais.sst": args[0].(int32), "sNssais.sd": args[1].(string)}
  </code></pre>
  
  <p>but other inputs do not work even if set the type casting to the args
  Any idea how i can use the mongodb logical $or in this case?</p>