0

This is part of my collection schema in mongodb:

{ "_id" : ObjectId("55e1eef5255da6d384754642"), "name" : [ "Web, Mobile & Software Dev", "Movil y desarrollo de software" ] } { "_id" : ObjectId("55e1f2d0255da6d38475464b"), "name" : [ "IT & Networking", "TI y Redes" ] } ...

Right now i can get the info like this:

 err := r.Coll.Find(bson.M{}).Select(bson.M{"name": bson.M{"$slice": []int{1, 1}}}).All(&result.Data)

but i want "name" to return a string instead of a single value array, so i dont have to index it inside my frontend if no need.

Raul Gomez
  • 620
  • 7
  • 15
  • so i will have to loop and change it myself for all records?, isnt there like a concat array with string to become string or a casting or something, sure? – Raul Gomez Aug 30 '15 at 20:46

1 Answers1

0

very limited comments i need 2000 poits for editing my post and add more things it seems, this is not answer but maybe, so i have to loop it?, isnt better way?

err := r.Coll.Find(bson.M{}).Select(bson.M{"name": bson.M{"$slice": []int{1, 1}}}).All(&result.Data)                                            
  if err != nil {                                                                                                                                 
      return result, err                                                                                                                          
  }                                                                                                                                               

  type skillnew struct {                                                                                                                          
      Id   bson.ObjectId `json:"id,omitempty" bson:"_id,omitempty"`                                                                               
      Name string        `bson:"name,omitempty" json:"name,omitempty"`                                                                            
  }                                                                                                                                               

  skillsallnew := make([]skillnew, len(result.Data))                                                                                              
  for i := range result.Data {                                                                                                                    
      skillsallnew[i] = skillnew{result.Data[i].Id, result.Data[i].Name[0]}                                                                       
  }    
Raul Gomez
  • 620
  • 7
  • 15