示例#1
0
func BuildMongoWhere(where *simplejson.Json, primaryKey string) bson.M {
	mongoWhere := bson.M{}
	for key, value := range where.MustMap() {
		switch key {
		case "and", "or", "nor":
			mongoWhere["$"+key] = buildMongoWhereByArray(
				where.Get(key),
				primaryKey,
			)
			continue

		case primaryKey:
			mongoWhere["_id"] = value
			continue
		}
		mongoWhere[key] = value
	}
	return mongoWhere
}