How to retrieve all tokens from a table that are not listed on another table?

i have a table where there are all the NFTs that are created called EthNFTOwners
and another table that has the nfts listed on the marketplace which is ListedItems

how do i retreive the nfts from the first table that are not in the second table? so basically the nfts that are not listed on the marketplace?

(on the cloud functions)

You could do two queries and then filter.

lets say i queried the results like this:
const listedItems = await query.find();
const myItems = await query2.find();

i will have to loop through everything? to filter? its not practical…
how can i get all the items in myItems that are not in listedItems

you can do a hash map / dict from the results of one query, and then when you loop the second query you can search fast in that hash map.

cant i in someway put a “foreign key” that links that item in the other table? and query it in one query? if i have 1 000 000 items looping through them is really bad …

I would have tried pagination and limiting my query, but this wouldn’t do it because the items in the other table might be in the end so I feel trying to make it all in one query is DA WAY

how many items you assume that you have in those two tables?
1.000.000 in EthNFTOwners? how many in ListedItems?

right now i have less than 100 in both, but later it will be more than 100 000, and ofcourse listeditems cannot pass the total amount of ethNFTOwners so either equal or less

You want that for a particular user address, I guess, and not for all the contents that are in ethNFTOwners? as in ethNFTOwners you will have data from all your users.

1 Like

true, for the current request, i want to retrieve all the items for a certain user(address) that are not listed on the marketplace

then I guess that the number of listed items on the marketplace for that user will be relatively small, now the problem would be if the user has 1.000.000 nft items in his address.

It may be possible to do a single query, it is mongo db syntax there, but I don’t know the syntax exactly.

yea all we have to do is do an outer join between the two tables and that would do the trick
but idk how to make it in the cloud functions syntax if its the same as mongoDB then i could google it

cause i also dont know anything about mongo db :stuck_out_tongue:

you can also do a google search on how to do it with Parse.com