update AssignOther

This commit is contained in:
Hoang 2021-12-24 09:38:49 +07:00
parent 57ea2d882a
commit 81df358020
1 changed files with 13 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package model
import ( import (
"github.com/Selly-Modules/mongodb" "github.com/Selly-Modules/mongodb"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/options"
) )
@ -75,7 +76,18 @@ func (q *CommonQuery) AssignOther(cond bson.M) {
// Query fields in other object // Query fields in other object
if len(q.Other) > 0 { if len(q.Other) > 0 {
for key, value := range q.Other { for key, value := range q.Other {
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 cond["other."+key] = value
} }
} }
}
} }