From 81df358020a809a04e88113079b8461145a1bc08 Mon Sep 17 00:00:00 2001 From: Hoang Date: Fri, 24 Dec 2021 09:38:49 +0700 Subject: [PATCH] update AssignOther --- model/query.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/model/query.go b/model/query.go index e3256cb..8f3fb87 100644 --- a/model/query.go +++ b/model/query.go @@ -3,6 +3,7 @@ package model import ( "github.com/Selly-Modules/mongodb" "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo/options" ) @@ -75,7 +76,18 @@ func (q *CommonQuery) AssignOther(cond bson.M) { // Query fields in other object if len(q.Other) > 0 { for key, value := range q.Other { - cond["other."+key] = value + switch v := value.(type) { + case []primitive.ObjectID: + cond["other."+key] = bson.M{ + "$in": v, + } + case []string: + cond["other."+key] = bson.M{ + "$in": v, + } + default: + cond["other."+key] = value + } } } }