giorgionasis
giorgionasis

Reputation: 394

Parse Server Cloud Code Query to Pointer

this is the structure of my Database with the classes:

User -> objectId (String) username (String)

Friends -> objectId (String) toUser (Pointer <_User> ) fromUser (Pointer <_User> )

My goal is to retrieve the users with the usernames, which matches the columns toUser and fromUser with a specific Id. The Pointer of toUser and fromUser variable is the objectId of the table "User"

How my query should be?

I tried this one but it doesn`t work

Parse.Cloud.define('FriendsQuery', function(req,res) {
const friends = new Parse.Query("Friends");
friends.equalTo("toUser","fEjQgAPvDO");
const userQuery = new Parse.Query("User");    

userQuery.matchesQuery('friend', friends);
userQuery.find().then((results) => {
    res.success(results);
})
.catch(() =>  {
  response.error("user lookup failed");
});
});

I have included only the toUser column in this query

Any idea?

Thank You

Upvotes: 0

Views: 855

Answers (2)

geek1706
geek1706

Reputation: 980

The third line should look like this

friends.equalTo("toUser", { "__type": "Pointer", "className": "_User", "objectId": "fEjQgAPvDO" })

Upvotes: 0

Alon Raskin
Alon Raskin

Reputation: 63

The third line in your code should look like this

friends.equalTo("toUser",{__type:"Pointer", className:"User", objectId:"fEjQgAPvDO"});

  • __type is always going to be Pointer
  • className is the name of the collection where the objectId is stored. In other words its the 'table' where the Pointer is pointing to
  • objectId is the ID in that 'table/collection'

Upvotes: 0

Related Questions