Ted7364671
Posts: 0
Joined: Wed Feb 04, 2015 8:46 pm

Trying to find all matches between database collections

I'm trying to find all matches between database collections - that is, search Collection B for all values in a given column in Collection A.

Collection A:
A
B
D

Collection B:
A
C
D

Query Returns:
A
D

Currently I am using a list service to put the Collection A values into local storage but I think the problem lies with how to map it to the "where" in my Collection B query service.

I feel like this should be straightforward but I've poured over the documentation and only found examples with the where defined as a static/default value or mapped to a single input. How do I search for any match out of a list of items?

Thanks in advance!

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

Trying to find all matches between database collections

Hi Ted,

Yes your way is correct.

To put all items from A collection to WHERE query of B collection you need to use: "$in" clause.

More details here: http://devcenter.appery.io/documentat...

Here is a example code:

pre

var arrayFromACollection = ["a", "b", "c"];

var whereObject = {"studentId": {"$in": arrayFromACollection } };

return JSON.stringify(whereObject);

/pre

Regards.

Ted7364671
Posts: 0
Joined: Wed Feb 04, 2015 8:46 pm

Trying to find all matches between database collections

Cool, thanks -

So how do I fetch the array from local storage (instead of defining it)?
I tried . . .

var Titlearray = localStorage.getItem("w_Title");
var whereObject = {"Title": {"$in": Titlearray } };
return JSON.stringify(whereObject);

but it didn't work. Do I need mapping?

Image

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

Trying to find all matches between database collections

Hi Ted,

Not sure what you have in your LSV with name "w_Title".

But if you have there JSON array - you can use following JS code:

pre

var TitlearrayString = localStorage.getItem("w_Title");
var Titlearray = JSON.parse(TitlearrayString);
var whereObject = {"Title": {"$in": Titlearray } };
return JSON.stringify(whereObject);

/pre

Regards.

Ted7364671
Posts: 0
Joined: Wed Feb 04, 2015 8:46 pm

Trying to find all matches between database collections

I tweaked the list service to local storage mapping to make it a JSON array and that works great! Thank you very much, Yurii -

John Chaudhry
Posts: 0
Joined: Sun Nov 22, 2015 9:25 am

Trying to find all matches between database collections

Hi Yurri,

This is very useful and almost solves my problem but I am not sure how to get an array in a local storage variable into this.

The LSV array contains strings "1", "2", "3". I am not sure how to get them into the Titlearray variable above.

Cheers,

John

John Chaudhry
Posts: 0
Joined: Sun Nov 22, 2015 9:25 am

Trying to find all matches between database collections

Fixed - thanks Sergiy.

Return to “Issues”