Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is Parse Query Constraints not supported ? #211

Closed
anwar-al-jahwari opened this issue Feb 3, 2016 · 22 comments
Closed

is Parse Query Constraints not supported ? #211

anwar-al-jahwari opened this issue Feb 3, 2016 · 22 comments
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@anwar-al-jahwari
Copy link

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.

@armenkh
Copy link

armenkh commented Feb 3, 2016

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

@rmistry75
Copy link

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.

@gfosco
Copy link
Contributor

gfosco commented Feb 5, 2016

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 gfosco added the type:bug Impaired feature or lacking behavior that is likely assumed label Feb 5, 2016
@bodhaguru
Copy link

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.

@petek157
Copy link

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

@nlutsenko
Copy link
Contributor

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.

@rmistry75
Copy link

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!

@marcinwalus
Copy link

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?

@flovilmart
Copy link
Contributor

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

@marcinwalus
Copy link

marcinwalus commented Dec 1, 2016

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

@flovilmart
Copy link
Contributor

What version of parse server are you using?

@marcinwalus
Copy link

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

@marcinwalus
Copy link

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"}}]}

@flovilmart
Copy link
Contributor

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

@marcinwalus
Copy link

@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.

@flovilmart
Copy link
Contributor

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

@marcinwalus
Copy link

@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.

@flovilmart
Copy link
Contributor

Awesome! Glad to know!

@hbreumelhof
Copy link

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();

@flovilmart
Copy link
Contributor

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

@hbreumelhof
Copy link

[36mverbose[39m: RESPONSE from [GET] /parse/login?username=xxxxx&password=********: {
  "response": {
    "objectId": "xxxxx",
    "createdAt": "2013-08-02T07:54:27.196Z",
    "updatedAt": "2016-08-15T05:28:06.727Z",
    "username": "xxxxx",
    "_perishable_token": "STrmFAuxuU466YckZL8EipolQ",
    "sessionToken": "r:445151684679df12989da5c124b16181"
  }
} objectId=xxxxx, createdAt=2013-08-02T07:54:27.196Z, updatedAt=2016-08-15T05:28:06.727Z, username=xxxxx, _perishable_token=STrmFAuxuU466YckZL8EipolQ, sessionToken=r:445151684679df12989da5c124b16181
[36mverbose[39m: REQUEST for [GET] /parse/classes/reportIt?&where=%7b%22createdAt%22%3a%7b%22%24gt%22%3a%222015-12-31T13%3a30%3a00Z%22%7d%7d: {} method=GET, url=/parse/classes/reportIt?&where=%7b%22createdAt%22%3a%7b%22%24gt%22%3a%222015-12-31T13%3a30%3a00Z%22%7d%7d, x-parse-application-id=xxxx, x-parse-rest-api-key=xxxx, x-parse-session-token=r:445151684679df12989da5c124b16181, host=ausyd5752:1337, 
[36mverbose[39m: RESPONSE from [GET] /parse/classes/reportIt?&where=%7b%22createdAt%22%3a%7b%22%24gt%22%3a%222015-12-31T13%3a30%3a00Z%22%7d%7d: {
  "response": {
    "results": []
  }
} results=[]

So url is /parse/classes/reportIt?&where=%7b%22createdAt%22%3a%7b%22%24gt%22%3a%222015-12-31T13%3a30%3a00Z%22%7d%7d . This seems to work on Parse but not Parse Server. Version I'm running is 2.3.2.

@hbreumelhof
Copy link

@flovilmart any thoughts on what the issue may be?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

10 participants