|
|
@ -195,17 +195,20 @@ func (d *Database) createAggregateLoad(target interface{}, composed *query.Query |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
isSlice := el.Field(i).Kind() == reflect.Slice |
|
|
|
field := elType.Field(i) |
|
|
|
|
|
|
|
fieldType := field.Type |
|
|
|
|
|
|
|
|
|
|
|
typ := el.Field(i).Type() |
|
|
|
isSlice := fieldType.Kind() == reflect.Slice |
|
|
|
if typ.Kind() == reflect.Slice { |
|
|
|
if isSlice { |
|
|
|
typ = typ.Elem() |
|
|
|
fieldType = fieldType.Elem() |
|
|
|
} |
|
|
|
} |
|
|
|
if typ.Kind() != reflect.Ptr { |
|
|
|
|
|
|
|
|
|
|
|
isPtr := fieldType.Kind() != reflect.Ptr |
|
|
|
|
|
|
|
if isPtr { |
|
|
|
panic(fmt.Errorf("preload field should have ptr type")) |
|
|
|
panic(fmt.Errorf("preload field should have ptr type")) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
lookupCollection := d.GetCollectionOf(reflect.Zero(typ).Interface()) |
|
|
|
lookupCollection := d.GetCollectionOf(reflect.Zero(fieldType).Interface()) |
|
|
|
lookupVars := primitive.M{"selector": "$" + localField} |
|
|
|
lookupVars := primitive.M{"selector": "$" + localField} |
|
|
|
lookupPipeline := primitive.A{ |
|
|
|
lookupPipeline := primitive.A{ |
|
|
|
primitive.M{"$match": primitive.M{"$expr": primitive.M{"$eq": primitive.A{"$" + foreignField, "$$selector"}}}}, |
|
|
|
primitive.M{"$match": primitive.M{"$expr": primitive.M{"$eq": primitive.A{"$" + foreignField, "$$selector"}}}}, |
|
|
|