收藏
回答

云开发添加数据报错errMsg: [FailedOperation.Insert] bulk w?

新建的集合

Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID 00e5fcc8-2dfd-11eb-b2eb-5254002d4a45, cloud function service error code -504002, error message Error: errCode: -502001 database request fail | errMsg: [FailedOperation.Insert] bulk write error: [{[{E11000 duplicate key error collection: tnt-9faylinha.LostOrder index: location dup key: { : 3887078034246690233 }}]}, {<nil>}]; 

wxml

_updateLost: function (cloudPath, cloudPathVideo) {
    wx.cloud.callFunction({
      name: 'add_Goods',
      data: {
        req_type: 'Lost',
        lostType: this.data.lostType,
        lostDesc: this.data.currentContent,
        lostName: this.data.lostName,
        radiocheck: this.data.radiocheck,
        lostIDcard: this.data.lostIDcard,
        lostTime: this.data.lostTime,
        lostLocation: this.data.lostLocation,
        latitude: Number(this.data.latitudes),
        longitude: Number(this.data.longitudes),
        lostFenceID: this.data.lostFenceID,
        lostFenceName: this.data.lostFenceName,
        contact: this.data.currentContactWay,
        images: cloudPath,
        video: cloudPathVideo,
        createAt: formatTime(new Date()),
      }
    }).then(res => {
      console.log("添加失物招领信息成功:", res.result)
      wx.hideLoading()
      wx.redirectTo({
        url: '/pages/lostChannel/lostChannel',
      })
    }).catch( err => {
      console.log(err)
    })
  },


云函数

exports.main = async (event, context) => {
    const wxContext = cloud.getWXContext()
    const req_type = event.req_type
    switch (req_type) {


        case "Lost":
            return addLost();


        default: {
            return
        }
    }


    function addLost() {
        return db.collection('LostOrder').add({
            data: {
                lostType: event.lostType,
                lostDesc: event.lostDesc,
                lostName: event.lostName,
                radiocheck: event.radiocheck,
        lostIDcard: event.lostIDcard,
                lostTime: event.lostTime,
                lostLocation: event.lostLocation,
                location: db.Geo.Point(event.longitude, event.latitude),
                lostFenceID: event.lostFenceID,
                lostFenceName: event.lostFenceName,
                contact: event.contact,
                images: event.images,
                video: event.video,
                createAt: event.createAt,
                userId: wxContext.OPENID,
                status: 0
            }
        })
    }
}
回答关注问题邀请回答
收藏

1 个回答

  • Qiu (吉²)
    Qiu (吉²)
    2020-11-24

    已解决:索引改成非唯一

    2020-11-24
    有用 2
    回复 1
    • Jhou旭
      Jhou旭
      2021-03-03
      已解决,感谢
      2021-03-03
      回复
登录 后发表内容
问题标签