Page 1 of 2

DB Update with WHERE and clause in JS doesn't work

Posted: Sun Aug 24, 2014 9:46 am
by Dmitrij Kudrin

Hello,
I have made DB update service with $set. Update it self works, but when I try to add WHERE clause with JS it doesn't work. I have tried many variations. RETURN function in JS doesn't work correctly. How to do it right?
On screenshot you can see mapping with local storage variable. It's a final goal. Actually JS must be so: return '{"nname":"' + value + '"}';
But as I can see WHERE clause works only when I add clause as "Default value" parametr in service request. But not when I try to use JS RETURN operator.
Thank you for help!

Image


DB Update with WHERE and clause in JS doesn't work

Posted: Sun Aug 24, 2014 5:21 pm
by Kateryna Grynko

Hi Dmitrij,

This should be working properly. Is the query executed without errors?
Could you please try setting a value of parameter 'where' in Test tab and let us know the result?


DB Update with WHERE and clause in JS doesn't work

Posted: Mon Aug 25, 2014 7:28 am
by Dmitrij Kudrin

Hi Katya,
1) Yes there is error "PUT https://api.appery.io/rest/1/db/colle... 400 (Bad Request) " in console.

code: "DBSP007"
description: "Serialization error"

Link on app:
http://appery.io/app/mobile-frame?src...

You can Sign Up as new user in app. Watch Position button will try to set DBlat field on value "30" for your user in DB collection DBpositions. But with no success.

2) "Could you please try setting a value of parameter 'where' in Test tab and let us know the result?"
By tetsting of service all works great:

Image


DB Update with WHERE and clause in JS doesn't work

Posted: Mon Aug 25, 2014 8:26 am
by Dmitrij Kudrin

To 1)
Note, that after sign up in my app, you must enter EMAIL and password to login.


DB Update with WHERE and clause in JS doesn't work

Posted: Mon Aug 25, 2014 3:21 pm
by Dmitrij Kudrin

I have shared app and DB with a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a.


DB Update with WHERE and clause in JS doesn't work

Posted: Mon Aug 25, 2014 3:47 pm
by Illya Stepanov

Hi -

We can see it now, thank you! We will check it and post an update here soon.


DB Update with WHERE and clause in JS doesn't work

Posted: Tue Aug 26, 2014 12:16 am
by Yurii Orishchuk

Hi Dmitrij,

Please follow these steps to get it work:

1 Open mapping for your update service.

2 Click "Add JS" on "where" request parameter. And populate it with following code:

pre

var whereObject = {"nname": value};
return whereObject;

/pre

3 Click "Add JS" on "operatins" request parameters. And populate it with following code:

pre

var operationsObject = {"$set":{"DBlong":"30"}};

return operationsObject;

/pre

That's all.

Regards.


DB Update with WHERE and clause in JS doesn't work

Posted: Tue Aug 26, 2014 3:50 am
by Dmitrij Kudrin

Ok, Thank you! Didn't thought it must work this way.
May be useful for others.


DB Update with WHERE and clause in JS doesn't work

Posted: Tue Aug 26, 2014 5:59 am
by Dmitrij Kudrin

Sorry, another problem with this.

http://devcenter.appery.io/documentat...

I try to set WHERE clause with $ne not equal to storage value (email).
You can see JS in ShowFriendsService mapping.

var whereObject2 = {"nname": {"$ne":value}};
return whereObject2;

It doesn't work. I get all records from collection.

Image


DB Update with WHERE and clause in JS doesn't work

Posted: Tue Aug 26, 2014 6:02 am
by Dmitrij Kudrin

I have made Alert with JSON.stringify(whereObject2), that you can see on screenshot. It shows that email comes with " " and all seems to be right. But it doesn't work.