2019-02-27 11:58



Im new in Golang and Im building a Golang CRUD using mgo framework to practice. When I insert one element using mgo, is inserted two times instead of one time, I ckecked it in MongoDB Compass Community. This is my repository

This is a picture showing how is being saved in my database:

enter image description here

Can anybody help me?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dpkk8687 dpkk8687 2年前

    Your code inserts a single document only. If it would insert 2, properties (except the _id field) would be identical / same.

    And your 2 documents have different time field, thus they are from 2 different runs.

    So what you see is the result of 2 different runs (2 seconds away from each other), either by you or by your IDE.

    点赞 评论 复制链接分享