我正在使用解析服务器云功能来使用主键查询类。类对象具有ACL,以允许只读该对象的用户。查询给我零结果。但是,一旦我将测试对象上的ACL更改为公共读/写,云函数查询就会为我提供所需的对象。据我所知,使用主键我应该在查询对象。有谁知道这里的问题是什么?
const mQuery = new Parse.Query('MyClass');
mQuery.equalTo('objectId', mObjectId);
const result = await mQuery.first(null, {useMasterKey : true});
console.log("mQuery",mQuery);
console.log("result",result);
if (!result) {
throw new Error('no data found.');
}
这里结果记录为未定义。将对象公开后,结果就是公共对象。我正在使用解析服务器3.x。
[first仅接受一个参数,因此重写为:
const result = await mQuery.first({ useMasterKey : true });
使用等于3.x的Parse Server版本,您可以执行以下操作:
Parse.Cloud.define("TestCloudCode", async (request) => {
const query = new Parse.Query(Parse.User);
const objectId = request.params.objectId;
const results = await query.get(objectId, {useMasterKey:true});
return results;
});
调用:
curl -X POST \
-H "X-Parse-Application-Id: ${APPLICATION_ID}" \
-H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
-H "Content-Type: application/json" \
-d '{ "objectId": "${Replace_with_your_objectId}" }' \
https://parseapi.back4app.com/functions/TestCloudCode