查询整个类与类中的第一个对象 [英] Query entire class vs first object in the class
问题描述
在我的云代码中,我想检索消息"类中的第一个对象.然后我想从该对象中获取一些信息,将其发送到另一个类,最后从我最初从中提取的消息"类中删除该对象.
In my cloud code I want to retrieve the first object in the "Messages" class. Then i want to grab some information from that object, send it to another class, and finally delete that object from the "Messages" class i originally pulled it from.
我的问题是我是否需要查询整个Messages"类才能获取其中的第一个对象?我不想因为代码效率低下而降低我的应用速度.
My question is do i need to query the entire "Messages" class just to get the first object in it? I don't want to slow down my app due to inefficient code.
Parse.Cloud.afterSave("sendMessage", function(Parse.Message, response) {
var body = null;
var senderName = null;
var senderId = null;
var randUsers = [];
var query = new.Parse.Query(Parse.Message);
query.find({
success: function(results){
body.push(results[1].get("messageBody"));
senderName.push(results[1].get("senderName"));
senderId.push(results[1].get("senderId"));
response.success(getUsers);
},
error: funtion(error){
response.error("Error");
}
});
});
为避免混淆:getUsers"是任意函数调用.
to avoid confusion: "getUsers" is an arbitrary function call.
推荐答案
要从类中检索条目,您需要查询表.但是,您的问题是获取不需要获取所有记录的第一条记录.从您的代码中,我可以看到您获得了结果数组的第一条记录 (result[1]).您可以应用该解决方案;获取要查询的类的第一条记录.您可以通过两种方式做到这一点;您可以为查询设置限制 1,也可以使用 first() 方法.Parse.Query JS API 链接如下;
To retrieve entry from class, you need the query the table. However, your problem is getting the first record which does not require getting the all record. From your code I can see that you get the first record of result array (result[1] ). You can apply the solution; getting the first record of the class that you want to query. You can do it via two ways; either you can set the limit 1 to your query or you can use the first() method. The Parse.Query JS API link is below;
https://parse.com/docs/js/symbols/Parse.查询.html
检查限制和第一种方法.希望这可以帮助.问候.
Check the limit and first methods. Hope this helps. Regards.
这篇关于查询整个类与类中的第一个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!