How to see original mongodb queries?

For example Parse.Query has an machesKeyInQuery option. How does parse handle this? Whats the mongo qeury for this option? I couldn’t find on source code. I looked the databaseController.

Also Is there any way to see how time it took to execute a query ? I dound explain() mehod. But docs dont say anything.

1 Like

That may be because the query is not entirely composed by Parse Server but also the Parse JS SDK. You can look here for a starting point:

As you correctly pointed out, you can use the explain command to get the query execution time. However, there are several caveats, see the MongoDB docs.

2 Likes

Thank you very much.

Hey. I have one more question. How does parse server handles relations? Docs says parse handle joints on server level so postgress has no advantage

For example if i use doesntMatchKeyInQuery option. Like this

query.doesntMatchKeyInQuery("key","innerKey",otherQuery);

What happens? Does parse run “otherQuery” first then run main query based on first query result? Or everything handled in database level? İ looked source codes but i didn’t understand my knowledge is not enough to understand.

Can you please explain?

Parse Server run the inner query to retrieve all object keys and then run the outer query.

1 Like

Then I guess There is no difference between this:

var userQuery = new Parse.Query(Parse.User);
userQuery.equalTo("private",false);

var postQuery = new Parse.Query(Post);
postQuery.matchesQuery("user",userQuery);

and this:

 var userQuery = new Parse.Query(Parse.User);
 userQuery.equalTo("private",false);
 const userList = await userQuery.find();

 var postQuery = new Parse.Query(Post);
 postQuery.containedIn("user",userList);

Am I right?

They should have the same result. In terms of performance, there are some differences:

  • if you are running case two in the client side, you will have two api calls going to the server, and it will probably be slower.
  • if you are running case two in cloud code function, make sure to use the directAccess experimental option, so you will avoid the requests going to the app as an api call and running a longer router. But even in the case you have directAcces set to true, case 1 should be slightly faster as it will require less verifications and transformations since it is a single operation.
1 Like

Thank you very much.

Edit:

İ have enabled directAccess.

What if we use master key? I’m following back4app security tutorial where we disable all CLP for every class and handle everything inside cloud code with master key.

İ believe if we use master key , verifications etc will be minimized. Right?

Even though a single query will be slightly better in terms of performance because of the mongo to parse / parse to mongo transformations. Also, if you go with the two queries approach, make sure to use select function to only select the fields you need in the inner query and also you will have to take care with the objects limit in the first query in the case you have setup any default value for your parse server.

2 Likes