Skip to content

Proper way of using $or operator in mgm #54

Discussion options

You must be logged in to vote

Hi @amirhossein-shakeri-work
It can be something like this:

type Person struct {
	mgm.DefaultModel `bson:",inline"`
	Name             string  `json:"name" bson:"name"`
	Age              int     `json:"age" bson:"age"`
	Weight           float64 `json:"weight" bson:"weight"`
}

func main() {
	persons := make([]*Person, 0)
	err := mgm.Coll(&Person{}).SimpleFind(&persons, bson.M{"$or": bson.A{
		bson.M{"age": bson.M{"$gt": 20}},
		bson.M{"weight": bson.M{"$lt": 70}},
	}})
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@amirhossein-shakeri
Comment options

@mehran-prs
Comment options

Answer selected by amirhossein-shakeri
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants