Query has stopped working

For some reason this query doesn’t work, I isolated the AIIMAGES database query and it worked but when added back it did not work( box139 doesn’t not respond) . The AIIMAGES database is a Members generated and updatable database and the dataset .onReady is a Read and Write. Please how do I fix this.

$w ( “#dataset116” ). onReady (() => {
$w ( “#dataset67” ). onReady (() => {
let ItemObjai = $w ( “#dataset67” ). getCurrentItem ()
if (( ItemObjai . aiEligibilityStart < Date . now ())&&( ItemObjai . aiEligbilityEnd > Date . now ())){
let S = new Date ( ItemObjai . aiEligibilityStart )
let E = new Date ( ItemObjai . aiEligbilityEnd )

let amountofai = wixData . query ( “SEEKERS” )
. gt ( “_createdDate” , S )
let aiadded = wixData . query ( “SEEKERS” )
. isNotEmpty ( “aiImageSearch” )
let ownerr = wixData . query ( “SEEKERS” )
. eq ( “_owner” , ItemObjai . _owner )
let aimages = wixData . query ( “AIIMAGES” )
. gt ( “_createdDate” , S )
let mages = wixData . query ( “AIIMAGES” )
. isNotEmpty ( “image” )
let ownerrr = wixData . query ( “AIIMAGES” )
. eq ( “_owner” , ItemObjai . _owner )
amountofai . and ( aiadded ). and ( ownerr ). and ( mages ). and ( aimages ). and ( ownerrr )
. find ()
. then ( ( results ) => {
let numb = results . items . length

if ( numb < ItemObjai . ainumber ){
$w ( “#box139” ). hide ()
}
else if ( numb >= ItemObjai . ainumber ){
$w ( “#box139” ). show ()

}
})
. catch (( err ) => {
let errorMsg = err ;
});
}
else {
$w ( “#box139” ). show ()
}
})
})

It should something like:

wixData.query("SEEKERS")
.gt("_createdDate",S)
.isNotEmpty("aiImageSearch")
.eq("_owner",ItemObjai._owner)
.gt("_createdDate",S)
.isNotEmpty("image")
.eq("_owner",ItemObjai._owner) 
.find()

Thanks for the response, but this query is accessing two databases

@chidiejike So run two queries (one per each database collection):

Promise.all([
query1.find(),
query2.find()
])
.then(res => {
    let allItems = [res[0].items, res[1].items].flat();
    //and continue to work with allItems 
})

Thanks JD it works now, but does this bring all the queried items from the databases no matter the amount or does it have a .limit(1000)?

@chidiejike it’s up to 1000 per each of them (depends on the .limit() you set).
If you only need the total number use .count() instead .find().

Promise.all([
query1.count(),
query2.count()
])
.then(res => {
    let total = res[0] + res[1];
    //and continue working with total 
})

if you need both the first 2,000 items + the total in collection:

Promise.all([
query1.limit(1000).find(),
query2.limit(1000).find()
])
.then(res => {
    let first2kItems = [res[0].items, res[1].items].flat();
let total = res[0].totalCount + res[1].totalCount
    //and continue with first2kItems  and total
})