Ricardo Amaral
Posts: 0
Joined: Thu Mar 17, 2016 7:33 pm

retriving object data from a variable at server code

I could successfully query data from my database with this sentence:

var variableTest = Collection.query("db_id", "table_tb", params);

Now i need to retrieve the value inside one object (objectA) that is inside variableTest

When i try: var receiveObject = variableTest.objectA it always get null.

How to retrieve that data?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

retriving object data from a variable at server code

Hello Ricardo,

Please add preconsole.log(JSON.stringify(variableTest)); /pre right after Collection.query(...); to see full structure of the database response. It looks like that object has empty parameter "objectA"

Ricardo Amaral
Posts: 0
Joined: Thu Mar 17, 2016 7:33 pm

retriving object data from a variable at server code

Thank you Sergiy, console.log helped a lot!

Seems my return was in an array so I need to put the call for objects on a loop or call the object index directly - In my case variableTest[0] once I had a single return. The sample below is a good training for beginners like me :)

//simulate database return for a set of data
var variableTest= {
"people": {
"person": [{
"name": "Peter",
"age": 43,
"sex": "male"},
{
"name": "Zara",
"age": 65,
"sex": "female"}]
}
};

//Request specific object from variable - return will be 43
var return_first_age = variableTest.people.person[0].age

//Request specific object from variable - return will be 65
var return_second_age = variableTest.people.person[1].age

console.log(JSON.stringify(return_first_age));
console.log(JSON.stringify(return_second_age));

saurabh8122815
Posts: 0
Joined: Mon Mar 21, 2016 5:08 am

retriving object data from a variable at server code

hello sergiy,

this is saurabh.

i need your help. im having some problems regarding server code script.

i used server code script to retrieve required record from the database. for example, i have database name "MESSAGE_DB" in that i have collection named "MESSAGE" in that collection i have some fields listing below.

user1 ("string type")
user2 ("string type")
messages ("string type")
users ("array type")

for retrieving required record i used server code script as i mention abow.

now what i need to do is using users value ("which are in array form") "message" column should be access and all the messages should retrieve from the database according to the "users" value.

for example, sam send message to tom and tom message to sam they interact with each other and those messages stored in database named "MESSAGE_DB" as i mention above and user name ("sam & tom") will be stored in column named "users" ("array type"). now when i need to retrieve conversation of sam and tom then its return either all messages including other users who interacts with other users or only those messages which sent by the sam.

so, im stuck here. help me in that.

my question is, How can i retrieve conversion between sam and tom only?

Thanks,

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

retriving object data from a variable at server code

Hello Saurabh,
Please use combination of logical clauses OR ($or), AND ($and) for that: https://devcenter.appery.io/documenta...

Add a "criteria" to the variable "param":
preparam.criteria = {"or":[{"$and":[{"user1":"sam"},{"user2":"tom"}]},{"$and":[{"user1":"tom"},{"user2":"sam"}]}]};/pre

saurabh8122815
Posts: 0
Joined: Mon Mar 21, 2016 5:08 am

retriving object data from a variable at server code

hello sergiy,

Thanks for your reply. i used that code but it return null value. maybe its get confuse to fetching records in this code if i delete second condition then it return value of "sam" and "tom". or alternatively "tom" and "sam". but what for both.
how can i retrieve those messages which sent by "sam" to "tom" and "tom" to "sam"??

help me!!

Regards Saurabh

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

retriving object data from a variable at server code

Sample request above is used for getting all messages between these users.

Please use request for messages from sam to tom:
preparam.criteria = {"$and":[{"user1":"sam"},{"user2":"tom"}]}/pre

And for messages from tom to sam:
preparam.criteria = {"$and":[{"user1":"tom"},{"user2":"sam"}]}/pre

Return to “Issues”