title: Should I copy session for each operation in mgo?
body: <p>I want to <code>upsert</code> a list of record, so I have two choice, one just use one session, another copy a session for every record. So, as my opinion, first method may slower than the second, but will the first one cause too many session created?</p>
  
  <p>1.use one session</p>
  
  <pre><code>func (this *CvStoreServiceImpl) SetCvJobItemMeasureList(accessToken *base_datatype.ServiceAccessToken, versionPolicy string, jobItemList []*cv_common_type.CvJobItemMeasure) (err error) {
      session := this.session.Clone()
      defer session.Close()
  
      for _, jobItem := range jobItemList {
          objKey := &amp;orm.ItemIdKey{
              VersionName: versionPolicy, //XXX
              ItemId:      jobItem.ItemId,
          }
          obj := orm.ConvertToCvJobItemMeasureObj(versionPolicy, jobItem)
          _, err2 := this.jobMeasureCollection.With(session).Upsert(objKey, obj)
          if nil != err2 {
              err = &amp;common_error.NamedError{err2.Error()}
              this.logger.Println(err2.Error())
          }
      }
      return
  }
  </code></pre>
  
  <p>2.copy session for every record</p>
  
  <pre><code>func (this *CvStoreServiceImpl) SetCvJobItemMeasure(accessToken *base_datatype.ServiceAccessToken, versionPolicy string, jobItem *cv_common_type.CvJobItemMeasure) (err error) {
      session := this.session.Clone()
      defer session.Close()
  
      objKey := &amp;orm.ItemIdKey{
          VersionName: versionPolicy, //XXX
          ItemId:      jobItem.ItemId,
      }
      obj := orm.ConvertToCvJobItemMeasureObj(versionPolicy, jobItem)
      _, err2 := this.jobMeasureCollection.With(session).Upsert(objKey, obj)
      if nil != err2 {
          err = &amp;common_error.NamedError{err2.Error()}
          return
      }
      return
  }
  </code></pre>
  
  <p>then call this method in forloop:</p>
  
  <pre><code>for _, item := range cvMeasure.GetJobList() {
      err = this.SetCvJobItemMeasure(accessToken, versionPolicy, item)
      if nil != err {
          return
      }
  }
  </code></pre>