如题,在nodejs 后台运行了下面的云函数(不是小程序云开发服务器中的云函数),调用了小程序http api 获取数据,然后报错说是查询语句解析错误,看错误信息应该是查询语句中的格式不对,应该是 ${today},。但是因为有变量,请教大家如何解决。文档上面没有例子使用变量的,感谢! (rp是 request-promise 库)
... 其他代码
let today = processDate(new Date());
let token = "token value";
return rp({
url: `https://api.weixin.qq.com/tcb/databasequery?access_token=${token}`,
method: "POST",
json: true,
headers: {
"content-type": "application/json",
},
body: {
"env":"any-id",
"query": `db.collection("all_houses").where({house_upload_date: ${today}}).get()`
}
}).then((res)=>{
console.log("res: %O", res);
return res;
}).catch(err=>{
console.log("err: %O", err);
})
db.collection("all_houses").where({house_upload_date: ${today}}).get()这个语句在云开发控制台执行一下
let today = '2020-03-12';
db.collection('all_houses')
.where({
house_upload_date: today
})
.field({
name: true,
price: true,
})
.orderBy('price', 'desc')
.skip(1)
.limit(10)
.get()
{
"env":"test2-4a89da",
"query": "db.collection(\"geo\").where({done:true}).limit(10).skip(1).get()"
}