Re: [go-nuts] How to query mongodb
On Fri, Jan 17, 2020 at 2:11 AM wrote: > > Hi I have in my collection this JSON > > { > "allowedSnssaiList": [ > { > "allowedSnssai": { > "sst": 1, > "sd": "1" > }, > "allowedSnssai": { > "sst": 2, > "sd": "3" > } >} >] > } > how can query using the key sst and sd to return a documents matching the two > exact values? Example when i query using sst:1, sd :1 it should return the > documents but sst:1 and sd:3 should not. The problem am having is that when i > query using "find" using sst:1, sd:3 it still return this JSON. This is a mongodb question, it is not related to Go language. I suggest you read the mongodb query manuals. What you're looking for can be found under $elemMatch query. > > br > Abraham > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/32eb3edb-d9c0-4c17-a4d0-2df0014b47cc%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAMV2RqqEN0NPvhJrBG7K0hyMyGpwjaadSC3U1Gc1Mrxv6tvLhw%40mail.gmail.com.
[go-nuts] How to query mongodb
Hi I have in my collection this JSON { "allowedSnssaiList": [ { "allowedSnssai": { "sst": 1, "sd": "1" }, "allowedSnssai": { "sst": 2, "sd": "3" } } ] } how can query using the key sst and sd to return a documents matching the two exact values? Example when i query using sst:1, sd :1 it should return the documents but sst:1 and sd:3 should not. The problem am having is that when i query using "find" using sst:1, sd:3 it still return this JSON. br Abraham -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/32eb3edb-d9c0-4c17-a4d0-2df0014b47cc%40googlegroups.com.
Re: [go-nuts] How to query mongodb dynamically using Go interface
On Thu, Jan 16, 2020 at 8:03 AM wrote: > > Hi, > > I have been trying to create a dynamic mongodb query using golang interface > but the logical $or does not work. > It only return a documents when the input matches the bson.M{"sNssais.sst": > args[0].(int32), "sNssais.sd": args[1].(string)}. > other matches like bson.M{"amfInfo.taiList.tac": args}, etc does not work > even though a document in mongodb collection exist that matches the input > value. > Any idea as how to do this? The function is as below That depends on what's in args, and in amfInfo.taiList.tac, etc. args is an array, so if the *.tac fields are also arrays, you're looking for an exact match. Is that really the case? > > 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(&ip) > if err != nil { > return ip, false > } > return ip, true > } > > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/c2dca0c6-e3f7-4822-9b7f-b09102450293%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAMV2RqrOc%2BKzruMsbPF9JpCS59s7NQ%3DXjnsTQg-5vrgYs8id4Q%40mail.gmail.com.
[go-nuts] How to query mongodb dynamically using Go interface
Hi, I have been trying to create a dynamic mongodb query using golang interface but the logical $or does not work. It only return a documents when the input matches the bson.M{"sNssais.sst": args[0].(int32), "sNssais.sd": args[1].(string)}. other matches like bson.M{"amfInfo.taiList.tac": args}, etc does not work even though a document in mongodb collection exist that matches the input value. Any idea as how to do this? The function is as below 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(&ip) if err != nil { return ip, false } return ip, true } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/c2dca0c6-e3f7-4822-9b7f-b09102450293%40googlegroups.com.