parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

is Parse Query Constraints not supported ?

Open anwar-al-jahwari opened this issue 10 years ago • 22 comments

Hello ,

I have successfully migrate the database to mongodb and i uploaded parse server to google app engine , i tried to query a class called Category
it worked.However , when i try to do some Constrains like where equal to it didn't work.

the rest api ,shows the same result with or without constrains

screen shot 2016-02-03 at 5 03 57 pm

screen shot 2016-02-03 at 5 03 41 pm

in addition i have tried the same thing in android sdks and it didn't work when i put constrains only it works without the constrains.

anwar-al-jahwari avatar Feb 03 '16 13:02 anwar-al-jahwari

I have similar problems. Query with constrains returns all the elements of the Item, I reported in the for mum also: https://groups.google.com/forum/#!topic/parse-developers/rPxdWUNSagI

Doesn't properly work with Android SDK eather: http://stackoverflow.com/questions/35154414/parse-getinbackground-throws-invalidkeyname-exception

armenkh avatar Feb 03 '16 18:02 armenkh

Same problem here. Whenever I try to query (via REST API) using a "where" clause, the clause is ignored and instead I get ALL items of that class.

rmistry75 avatar Feb 04 '16 02:02 rmistry75

Ok, this is not supposed to be the case, obviously. Must be some difference from the various test scenarios we have. Will look at it very soon.

gfosco avatar Feb 05 '16 03:02 gfosco

Same problem for me too - when using REST API. It is giving error on line 83 in node_modules/parse-server/node_modules/body-parser/lib/types/json.js file - saying "Unexpected token ....". It is expecting only "{" or "[" there, whereas what is getting passed is "w" or "u" depending upon the query.

bodhaguru avatar Feb 10 '16 16:02 bodhaguru

I am having this issue as well. I see there are a number of "issues" regarding this topic but it doesn't seem as though any of them have resolved. I have tried using REST, PHP and JS and its seems like none are adhering to constraints. I apologize that I can't elaborate like others as I used Parse because Im not as advanced in programming to build this out my self. My issue seem like above that no matter what constraints I put on a query I get all objects in that class.

<?php

use Parse\ParseClient;
use Parse\ParseCloud;
use Parse\ParseObject;
use Parse\ParseQuery;
use Parse\ParseFile;
use Parse\ParseUser;
ParseClient::initialize('APPID', 'REST', 'MASTER');
ParseClient::setServerURL('http://URL:1377/parse');

$query = new ParseQuery("Product");

$query->equalTo("length", 9);
$object = $query->first();
echo $object->getObjectId();
?>

//Returns wrong objectId //Assuming its just the "first" object returned

Parse.initialize("APPID", "JSKEY");
    Parse.serverURL = 'http://URL:1377/parse';

    var Product = Parse.Object.extend("Product");
    var query = new Parse.Query(Product);
    //query.equalTo("length", 9);
    query.find({
      success: function(product) {
        // The object was retrieved successfully.
        console.log("Color: " + product[0].get("visualColor"));
        console.log("ID: " + product[0].id);
      },
      error: function(object, error) {
        // The object was not retrieved successfully.
        // error is a Parse.Error with an error code and message.
      }
    });

Logs blank and the incorrect id again assuming its just the first object returned. checking the count 5 objects are returned which is all of them and only 1 has the length of 9

curl -X GET \
>   -H "X-Parse-Application-Id: APPID" \
>   -H "X-Parse-Rest-API-Key: RESTKEY" \
>   -G \
>   --data-urlencode 'where={"objectId":"kVzk5HYB9k"}' \
>   http://URL:1377/parse/classes/Product

Curl returns list of all objects

petek157 avatar Feb 18 '16 20:02 petek157

Looks like we don't handle url queries in Classes to be passed as non-body parameters, this is definetly a bug, but for now as a workaround - use JSON body with method: GET inside of it.

nlutsenko avatar Feb 21 '16 07:02 nlutsenko

Hi, I'm not sure what the "workaround - use JSON body with method: GET inside of it." means. Can you please show us how to implement the workaround with an example. Perhaps you can show us how to fix the example listed above:

curl -X GET \

-H "X-Parse-Application-Id: APPID"
-H "X-Parse-Rest-API-Key: RESTKEY"
-G
--data-urlencode 'where={"objectId":"kVzk5HYB9k"}'
http://URL:1377/parse/classes/Product

What would the workaround solution look like for this curl request?

Thanks!

rmistry75 avatar Feb 22 '16 05:02 rmistry75

Hi! I just migrated app from Parse.com to Azure Managed services. I have everything working correctly (parse dashboard, etc.). Except this issue with "Query Constraints". From my Mac app when I ask for specific object in class with given "objectId" I'm getting all objects in class in return and not one specific. In Api Console in my parse dashboard I'm getting specific object correctly. @nlutsenko Is this issue fixed?

marcinwalus avatar Dec 01 '16 13:12 marcinwalus

@marcinwalus can you run parse server with VERBOSE=1 set and provide the server logs please?

flovilmart avatar Dec 01 '16 13:12 flovilmart

This is the query

let query = PFQuery(className: "Location")
query.whereKey("objectId", equalTo: locationObjectId)
query.includeKey("organization,city,city.country,city.country.language")

pfquerycontroller_m streaming_logs_-_microsoft_azure pfquerycontroller_m 2

marcinwalus avatar Dec 01 '16 13:12 marcinwalus

What version of parse server are you using?

flovilmart avatar Dec 01 '16 13:12 flovilmart

Parse Dashboard on my azure server says: "Server version: 2.2.25"

marcinwalus avatar Dec 01 '16 13:12 marcinwalus

Parse SDK is: 1.14.2 An issue is if whet execute this query against Parse.com app it works correctly. When I run it against my Azure parse server app it returns all objects in class.

When I use url grabbed from Dashboard API Console

curl 'https://....azurewebsites.net/parse/classes/Location?where=\{%22objectId%22:%2229COAmeqPP%22\}' -XGET -H 'X-Parse-Master-Key: 4243...' -H 'X-Parse-Application-Id: fb6...'

...it returns correctly only one row

{"results":[{"objectId":"29COAmeqPP","name":"Leilab 2","createdAt":"2016-09-05T13:31:54.285Z","updatedAt":"2016-09-21T13:56:29.876Z","city":{"__type":"Pointer","className":"City","objectId":"4OwGCKn8Pg"},"organization":{"__type":"Pointer","className":"Organization","objectId":"CdY1INFkSj"},"showOneMapOnly":true,"visible":true,"order":40,"mainAddress":{"__type":"Pointer","className":"Address","objectId":"zTS2qDuzfY"}}]}

marcinwalus avatar Dec 01 '16 14:12 marcinwalus

Ok, that helps :) and the parse-server version that is deployed on azure?

flovilmart avatar Dec 01 '16 14:12 flovilmart

@flovilmart I'm not 100% sure how to check that, sorry. but looking into "node_modules/parse-server/package.json" in my azure wwwroot folder I see "version": "2.2.25" (same as on my Parse Dashboard), so I think this is a version number.

marcinwalus avatar Dec 01 '16 14:12 marcinwalus

that's very odd then, i'll need to dig deeper into it, doesn't seem to occur with curl nor the JS SDK.

flovilmart avatar Dec 01 '16 14:12 flovilmart

@flovilmart Found it! And I need to say that it was partially my fault, however it should be handled in a better way so I think that this is still a bug. An issue was that server address I was passing to Parse configuration in my Mac app was "http://..." and not "https://...". After changing to https it works correctly with Parse on Azure.

marcinwalus avatar Dec 02 '16 16:12 marcinwalus

Awesome! Glad to know!

flovilmart avatar Dec 02 '16 16:12 flovilmart

This still doesn't seem to be working in the latest version of Parse Server. I'm using the following code where url is {parseInstance}/classes/reportIt?&where={"createdAt":{"$gt":"2016-12-31T13:30:00Z"}} . No constraints such as gte, gt, lte, lt etc work. The API docs state that this should still work in the new Parse Server. Is a fix planned for this? If not, how would I write a workaround for this?

                WebHeaderCollection parseHeaders = new WebHeaderCollection();
                parseHeaders.Add("X-Parse-Application-Id", applicationId);
                parseHeaders.Add("X-Parse-REST-API-Key", applicationKey);

                if (!String.IsNullOrEmpty(this.sessionToken))
                {
                    parseHeaders.Add("X-Parse-Session-Token", this.sessionToken);
                }

                WebRequest webRequest = WebRequest.Create(url);
                webRequest.Method = "GET";
                webRequest.Headers = parseHeaders;
                webRequest.Timeout = ConnectionTimeout;

                HttpWebResponse b = (HttpWebResponse)webRequest.GetResponse();

                Stream readerStream = b.GetResponseStream();
                StreamReader uberReader = new StreamReader(readerStream);

                String response = uberReader.ReadToEnd();

hbreumelhof avatar Jan 23 '17 02:01 hbreumelhof

@hbreumelhof can you provide the server logs when running with VERBOSE=1 ? It's likely your query Params are not properly encoded

flovilmart avatar Jan 23 '17 02:01 flovilmart