good morning!!!!

Skip to content
Snippets Groups Projects
Commit df1d2682 authored by Paul Xue's avatar Paul Xue
Browse files

allow non objectId tpe for mongo _id

parent 9752fdcc
No related branches found
No related tags found
No related merge requests found
......@@ -240,9 +240,11 @@ func (col *Collection) Append(item interface{}) (interface{}, error) {
}
// And other interfaces?
if setter, ok := item.(ObjectIdIDSetter); ok {
if err := setter.SetID(id); err != nil {
return nil, err
if _, ok := id.(bson.ObjectId); ok {
if setter, ok := item.(ObjectIdIDSetter); ok {
if err := setter.SetID(id.(bson.ObjectId)); err != nil {
return nil, err
}
}
}
......@@ -260,7 +262,7 @@ func (col *Collection) Exists() bool {
}
// Fetches object _id or generates a new one if object doesn't have one or the one it has is invalid
func getID(item interface{}) bson.ObjectId {
func getID(item interface{}) interface{} {
v := reflect.ValueOf(item)
switch v.Kind() {
......@@ -312,6 +314,8 @@ func getID(item interface{}) bson.ObjectId {
if bsonID.Valid() {
return bsonID
}
} else {
return v.FieldByName(fieldName).Interface()
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment