解决:bmob数据库类型,invalid type for key 'user_id', expected 'Pointer', but got 'String'

在这里插入图片描述
我用的是bmob作为数据库进行数据的存储,如上图所示,例如user_id字段,它是pointer类型,关联到user表。当我想直接使用
set操作进行数据插入时,发现报以下错误:

query.set('user_id',‘XXXXXXX’);
invalid type for key 'user_id', expected 'Pointer', but got 'String'

错误的意思就是user_id的数据类型是pointer,而我直接插入了一个string字段串。
解决办法:

const pointer = Bmob.Pointer('user');    //user为user_id字段关联的数据库表
const poiID = pointer.set('XXXXXXXXX');   //XXXXXXXXX指的是这条数据对应的user表id,也就是关联的user的主键
const query = Bmob.Query('authentication');   //authentication为我这条数据的数据库表名;
query.set('user_id', poiID);                 //接下来就可以做增删查改了,我这里做的是新增一条数据
query.save().then(res => {
      console.log(res)
    }).catch(err => {
      console.log(err)
    })

你可能感兴趣的:(其他)