Dmitrij Kudrin
Posts: 0
Joined: Tue Jul 08, 2014 2:47 pm

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

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

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

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?

Dmitrij Kudrin
Posts: 0
Joined: Tue Jul 08, 2014 2:47 pm

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

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

Dmitrij Kudrin
Posts: 0
Joined: Tue Jul 08, 2014 2:47 pm

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

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

Dmitrij Kudrin
Posts: 0
Joined: Tue Jul 08, 2014 2:47 pm

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

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

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

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

Hi -

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

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

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

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.

Dmitrij Kudrin
Posts: 0
Joined: Tue Jul 08, 2014 2:47 pm

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

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

Dmitrij Kudrin
Posts: 0
Joined: Tue Jul 08, 2014 2:47 pm

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

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

Dmitrij Kudrin
Posts: 0
Joined: Tue Jul 08, 2014 2:47 pm

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

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.

Return to “Issues”