diff --git a/lookup.go b/lookup.go index dfc5f4d..78f0843 100644 --- a/lookup.go +++ b/lookup.go @@ -156,10 +156,14 @@ func Lookup(db *mgo.Database, structField string, results interface{}, selector object := objectIDs[objectID] field := elV.FieldByName(structField) - if fieldIsPtr { - field.Set(reflect.ValueOf(object)) - } else { - field.Set(reflect.ValueOf(object).Elem()) + if object != nil && field.CanSet() { + objectVal := reflect.ValueOf(object) + + if fieldIsPtr { + field.Set(objectVal) + } else { + field.Set(objectVal.Elem()) + } } }