Parse.com doesNotMatchKeyInQuery not working with objectId and pointer - javascript

I'm trying to return a list a users who are not already in a friends join table on Parse.com but it seems that trying to match a pointer record with a users objectId will not work.
We could break this out into separate calls but that would be poor performance.
Has anyone solved this yet?
//Get users current friends
var myfriends = new Parse.Query("UserFriend");
myfriends.equalTo("myUserId",user);
//get users who are not already friends
var userQuery = new Parse.Query(Parse.User);
userQuery.doesNotMatchKeyInQuery("objectId", "theirUserId", myfriends);
userQuery.find().then(function(newfriends){
//do stuff with newfriends
//New friends should not include existing friends but it does..
});
Big thanks to anyone who can help.

I haven't tested this, but give it a shot.. From my comment: "have a query for Parse.User that matches key in query for user friends, against a user query that does not match that query". This might suffer the same problem.
var friendsQuery = new Parse.Query(Parse.User);
var myfriends = new Parse.Query("UserFriend");
myfriends.equalTo("myUserId",user);
friendsQuery.matchesKeyInQuery("objectId", "theirUserId", myfriends);
var userQuery = new Parse.Query(Parse.User);
userQuery.doesNotMatchQuery("objectId", friendsQuery);
//Assuming Cloud Code...
userQuery.find({ useMasterKey: true }).then(function(newfriends){
//do stuff with newfriends
});

I couldn't get this to work either.. Instead I used doesNotMatchQuery which worked find with pointers.

I had a similar problem and discovered you can't compare an objectId to a pointer object. So in the case above:
userQuery.doesNotMatchKeyInQuery("objectId", "theirUserId", myfriends);
theirUserId would need to be a string key containing the the actual alphanumeric Id, not a pointer.

This is a running issue in Parse Server
https://github.com/parse-community/parse-server/issues/4346

Related

Mongodb-Rest queries with like [duplicate]

My question is simple but i can not find exact solution. All articles have gor below a line of code:
collection.findOne({hello:'world_no_safe'});
Above codes does work and returns to me undefined error.But it is existed. Anyway, My exact solution is above. Please help me and teach me how to use regex by searching inside of the json api. ı want to use %mysearch data% as a regex expression. ı want to make text search which is used all sentences in json.
For example : i have a json:
[{"data":"Andreas Kollegger explains what kinds of questions you can answer with a graph database. It's not only the big sites that "},{"data":"X explains what kinds of questions you can answer with a graph database. It's not only the big sites that "}]
if i use this expression: collection.findOne({hello:'%Andreas%'});
it has to return first data. Below a real sample from my project.
var mongo = require('mongodb');
var Server = mongo.Server;
var Db = mongo.Db;
var server = new Server('ds053479.mongolab.com', 53479, {auto_reconnect : true});
var db = new Db('orient', server);
db.open(function(err, client) {
client.authenticate('testname', 'fsfsff', function(err, success) {
var collection = db.collection('Models');
collection.insert({Name:'test1'});
// Fetch the document
collection.findOne({Name:'%world_no_safe%'});
});
According to the MongoDB Manual you can use the $regex operator:
collection.findOne({Name: { $regex: '.*world_no_safe.*' }});

Add Query conditionals to related object's properties in parse.com with JS SDK

It is possible to sort and use conditionals to a related object in parse.com?
I have Users which have a pointer to profilePictures. I would like a query such as:
var query = new Parse.Query(Parse.User);
// include images
query.include("profilePicture");
// get only regular users
query.notEqualTo("isAdmin", true);
// who has uploaded an image
query.exists("profilePicture");
// and such image was updated in the last month
query.lessThanOrEqualTo("profilePicture.updatedAt", today);
query.greaterThanOrEqualTo("profilePicture.updatedAt", lastMonth);
// and order the resultset by profilePicture.updatedAt
query.ascending("profilePicture.updatedAt");
Unfortunatelly this returns a 105 error from parse.com as it can't find the property...
{"code":105,"error":"profilePicture.updatedAt is not a valid order key"}
All the posts I find are quite old (~2012) and maybe something changed lately. Any idea on how to achieve this?
For sorting I don't really care. I've alrady implemented a comparator, but I need to filter by date as I can't query for 1000's of profiles for nothing
You cannot achieve that with include and dot-notation. You better use inner queries for this:
var innerQuery = new Parse.Query("PICTURES"); // query on your profile picture class
innerQuery.lessThanOrEqualTo("updatedAt", today);
innerQuery.greaterThanOrEqualTo("updatedAt", lastMonth);
var query = new Parse.Query(Parse.User);
query.matchesQuery("profilePicture", innerQuery); // users that match the picture criteria
query.find({
success: function(users) {
// You get selected users with the profilePicture criteria
}
});

Cloud Code Not able to find users installations on Parse database

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.
I'm attempting to find all of the users that equal the "friendId" for a particular user and send notifications to those users.
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");
}
});
});
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);
If you try to explain your tables better, I can try to give you better advice :)
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

Parse.com security Role not saving

This is my first time playing around with security roles in Parse and I believe what I'm trying to do is fairly simple. I want to create a new security Role after I signup a new user using the afterSave trigger in CloudCode.
I've verified that this is being called and the roleName is correct, but nothing is being saved in the data browser. I feel like I'm missing something pretty basic here for this not to be working - is there a setting somewhere I need to turn on?
Parse.Cloud.afterSave(Parse.User, function(request, response) {
var user = request.object;
if (user.existed()) { return; }
var acl = new Parse.ACL();
acl.setPublicReadAccess(false);
acl.setPublicWriteAccess(false);
var roleName = user.get("email");
Parse.Cloud.useMasterKey();
var companyRole = new Parse.Role(roleName, acl);
console.log("Role = " + companyRole);
companyRole.save();
});
Found the solution. In Parse, you the name for a Role can only contains letters, numbers, and underscore. I was trying to set the role name as an email address, which contains '#' and '.'
I did a replace on these characters before I saved the name and worked perfectly. I wish Parse would've thrown an error if trying to save with invalid characters but problem solved now.

Why is matchesKeyInQuery is returning all results, not just those of the current user?

Using Parse.com and JavaScript SDK.
A fiddle can be found here. The results should be only badge 5 is returned not badge 8.
Trying to use the matchesKeyInQueryto achieve the following:
1 - Return results only for the current user only
2 - Only return results for the current user where the B_Notify column equals "Unread"
3 - Include access to columns "SentTo and "uploadedBy"
At the moment, the below query doesn't seem limited to just the current user as all results are being returned.
Also, I cannot get the query to work unless I repeat 'SentTo" in the NotificationTwo.matchesKeyInQueryquery
Can someone show me what I've done wrong, or how to correct it please?
var NotificationOne = new Parse.Query("myBadges");
NotificationOne.equalTo("B_Notify", "Unread");
var currentUser = Parse.User.current();
var NotificationTwo = new Parse.Query("myBadges");
NotificationTwo.include('SentTo', currentUser);
NotificationTwo.include('uploadedBy');
NotificationTwo.matchesKeyInQuery("SentTo", "SentTo", NotificationOne);
NotificationTwo.find({
According to the query you gave, I thought it could be rewrite as following:
var notificationQuery = new Parse.Query('myBadges');
notificationQuery.equalTo('B_Notify', 'Unread');
notificationQuery.equalTo('SentTo', Parse.User.current());
notificationQuery.include(['SentTo', 'uploadedBy']);
notificationQuery.find({ ...

Categories