Page 1 of 4

Multiple values for "where" in one database query

Posted: Wed Feb 06, 2013 6:16 pm
by Joseph Yeung

Hello, Tiggzi team.

I'm aware that when querying (request mapping) a tiggzi database, I can use javascript at the "where" parameter, e.g. {“Maker”:”Samsung”}.

but how about I have multiple values for querying, e.g. "where": maker is Samsung, Nokia, or Sony.

Also, in another case how about would like to query "where": maker is Samsung and model is Galaxy Note III?

Any help is appreciated!


Multiple values for "where" in one database query

Posted: Wed Feb 06, 2013 6:49 pm
by Kateryna Grynko

Hello Joseph,

http://docs.tiggzi.com/documentation/...

This might look like:
code{"Maker":{"$in": ["Samsung","Nokia"]}, "model":"Galaxy Note III"}/code
Conditions in several columns unit using logical AND. It means that in example above "Maker" is:
code{"$in": ["Samsung","Nokia"]} AND "model":"Galaxy Note III"/code


Multiple values for "where" in one database query

Posted: Wed Feb 06, 2013 7:11 pm
by Joseph Yeung

Thanks for you prompt reply. I would check it out.


Multiple values for "where" in one database query

Posted: Thu Feb 07, 2013 2:21 am
by Joseph Yeung

Hello!

Could you also tell how I put the expression in a custom ajax request? The setting item should be called "data" or whatever?

My guess:
precode
$.ajax({
dataType: 'json',
data: {"Maker":{"$in": ["Samsung","Nokia"]}, "model":"Galaxy Note III"},
url: 'https://api.tiggzi.com/rest/xxxxxx',
beforeSend: function (xhr) {
xhr.setRequestHeader('X-Tiggzi-Database-Id', 'xxxxx'); },

Code: Select all

         success: function (quizzes) {}, 
         type: "GET", 
         error: function () {}, 
     }); 

/code/pre

Thanks heaps.


Multiple values for "where" in one database query

Posted: Thu Feb 07, 2013 8:15 am
by Maryna Brodina

Hello!

codevar whereClause = {"Maker":{"$in": ["Samsung","Nokia"]}, "model":"Galaxy Note III"};

$.ajax({
dataType: 'json',
data: "where="+encodeURI(JSON.stringify(whereClause)),
url: 'https://api.tiggzi.com/rest/1/db/collections/xxx',
beforeSend: function (xhr) {
xhr.setRequestHeader('X-Tiggzi-Database-Id', 'xxxx');
},
success: function (quizzes) {},
type: "GET",
error: function () {}
});/code


Multiple values for "where" in one database query

Posted: Thu Feb 07, 2013 10:16 am
by Joseph Yeung

Thanks alooooooooooot!!


Multiple values for "where" in one database query

Posted: Fri Feb 08, 2013 12:24 am
by Joseph Yeung

Hi,

It was promising, but did not work out, with the returning response being 500 internal server error.

The question remains how to translate the following (underlined) cURL command into jquery:

Any thought is much appreciated.

Image


Multiple values for "where" in one database query

Posted: Fri Feb 08, 2013 1:59 am
by Joseph Yeung

Sorry, any reply on the above?


Multiple values for "where" in one database query

Posted: Fri Feb 08, 2013 8:13 am
by Maryna Brodina

Hello! Here is how to translate it into jQuery:

$.ajax({
data: encodeURI('where={"priority":"high"}'),
...
})

If you'll have server returning any error, you should check description of the error using Firebug or Chrome Developer Console (Network tab)


Multiple values for "where" in one database query

Posted: Fri Feb 08, 2013 9:46 am
by Joseph Yeung

I did check it out. Besides 500 internal server error, it said missing database id, which did not make much sense.