阅读背景:

Cloud Code无法在Parse数据库中找到用户安装

来源:互联网 

I have a Friends table that contains userIds for a user list of friends. The user column is a pointer to the User table and the friendId does the same.

我有一个Friends表,其中包含用户友情列表的userIds。 user列是指向User表的指针,friendId也是如此。

I'm attempting to find all of the users that equal the "friendId" for a particular user and send notifications to those users.

我试图找到所有与特定用户的“friendId”相等的用户,并向这些用户发送通知。

I've added a "user" column to my Installations table which is a pointer to "User" so that I can find my installations for specific users and send a push notification.

我在“安装”表中添加了一个“用户”列,这是一个指向“用户”的指针,以便我可以找到特定用户的安装并发送推送通知。

The issue I am having is I an unable to link those queries together to get send my push notifications to my list of friends.

我遇到的问题是我无法将这些查询链接在一起以将我的推送通知发送到我的朋友列表。

Any suggestions are helpful.

任何建议都有帮助。

My current cloud code

我目前的云代码

    Parse.Cloud.define("pushCheckIn", function(request, response) {
// Find users near with pending messages

var friendList = Parse.Object.extend("Friends");
var username = request.params.username;
var location = request.params.location;
var userQuery = new Parse.Query(friendList);

userQuery.equalTo("friendId", Parse.User);

// Find devices associated with these users
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.matchesQuery("user", userQuery);

var alertMsg = username + " checked-in at " + location;

Parse.Push.send({
  where: pushQuery,
  data: {
    alert: alertMsg,
    sound: "beep-shinymetal.caf",
    title: alertMsg
  }
}, {
  success: function() {
    response.success(alertMsg);
    // Push was successful
  },
  error: function(error) {
    response.error("push failed");
  }
});
});

2 个解决方案

#1


0  

Your description of your tables is complicated and I don't fully understand, however I think that new Parse.Query(friendList); should rather be new Parse.Query("Friends"); and userQuery.equalTo("friendId", Parse.User); doesn't make sense at all, if it is string you should use userQuery.equalTo("friendId", yourFriendIdString);

你对表的描述很复杂,我不完全理解,但是我认为新的Parse.Query(friendList);应该是新的Parse.Query(“朋友”);和userQuery.equalTo(“friendId”,Parse.User);完全没有意义,如果它是字符串你应该使用userQuery.equalTo(“friendId”,yourFriendIdString);

If you try to explain your tables better, I can try to give you better advice :)

如果你试图更好地解释你的表,我可以尝试给你更好的建议:)

#2


0  

The Installations table can not be queried directly without using the master key. To query the installations table, use

如果不使用主密钥,则无法直接查询“安装”表。要查询安装表,请使用

Parse.Cloud.useMasterKey();

before executing the query

在执行查询之前


分享到: