服务器端API文档没说可以使用自定义_id字段;
只有小程序端有可以使用自定义_id字段
客户端新增记录
直接写死一个_id
db.collection('xxx').add({
data:{
_id:'123456789',
hh:'hh'
}
})
插入成功后,后台看_id是123456789
//json对象转成json字符串
var jsonobj = res.data;
var jsonstr = JSON.stringify(jsonobj);
console.log("jsonstr==" + jsonstr)
var idstring = '"Id":';
var _idstring = '"_id":';
jsonstr = jsonstr.replace(idstring, _idstring);
jsonstr = jsonstr.replace(new RegExp(idstring, 'g'), _idstring);
console.log("jsonstr00==" + jsonstr)
let jsonobj2 = JSON.parse(jsonstr);
that.setData({
ProductStockTypeList: jsonobj2
})