where := bson.M{"$match": bson.M{"user_id": userId, "bank_id": bankId, "knowledge_points": bson.M{"$in": Knowledge}, "difficulty": difficulty}}
num := bson.M{"$sample": bson.M{"size": questionNum}}
err := repo.collection().Pipe([]bson.M{where, num}).All(&b)
if err != nil {
return nil, err
}
请教 以上代码 where 条件中 "knowledge_points": bson.M{"$in": Knowledge}, "difficulty": difficulty是可选项,如果有值才会进行匹配,请问该怎么写?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…