Is it possible to combine two databases in this way?

My purpose is first to check out who is the current logged in member and then query if that member is renting a specific video. “ExpiryDate1” is a field column in the “Rentingmembers” collection that either show an expiration time for renting Video 1 or no date at all if the member is not renting it. When someone rent that video the dark lamp image shall collapse and the flashing lamp image shall expand but it is not working and I don´t know why. Help would be greatly appriciated because I seem to be stuck with this forever and can not solve it by my own. Even a professional coder told me that it is a hard nut to crack.

I get no red markings so the problem is invisible for me.

import { currentMember , authentication } from ‘wix-members’ ;
import wixUsers from ‘wix-users’ ;
import wixData from ‘wix-data’ ;

let memberId , memberEmail ;

async function checkIfLoggedIn (){
const thisMember = await currentMember . getMember ();
return thisMember ? true : false ;
}
$w . onReady ( () => {

authentication . onLogin ( **async**  ( member ) => { 
  **const**  loggedInMember  =  **await**  member . getMember ();  
  memberId  =  loggedInMember . _id ; 
  memberEmail  =  loggedInMember . loginEmail ; 
  **return**  wixData . query ( "Members" ) 
  . eq ( "_id" ,  memberId ) 
  . find () 
  . then (( results ) => { 
    **if**  ( results . length  ===  0 ) { 
      console . log ( results . items [ 0 ]); 
    }  **else**  { 
    **return**  wixData . query ( "Rentingmembers" ) 
  . eq ( 'expiryDate1' ) 
  . find () 
  . then (( results ) => { 
    **let**  date  =  $w ( "#dataset5" ). getCurrentItem (). expiryDate1 ; 
    **if** ( results . items . length  >  0 ) { 
      console . log ( results . items [ 0 ]); 
    }  **else**  { 
    $w ( "#date1" ). text  =  date . toLocaleDateString () 
    $w ( "#image138" ). collapse (); 
    $w ( '#image139' ). expand (); 
        console . log ( date ) 
    } 
   }) 
   } 
 }) 
}) 

})
})

I have now watched and followed your posts for a long while.
I will now tell you why you still did not get a clear answer to your question.

The answer is simple → you never described your PROJECT-SETUP in DETAIL.

I will do it now for you.

Hello everybody, i have an issue, i do not know–> How to query a date field and show with a lamp the DB-field isn´t empty? ← inside of my database.

This is my project-setup:

  1. I am using a DATASET → (ID: #dataset5 ).
  2. My dataset is connected to → “Rentingmembers” - DATABASE .
  3. I have a repeater on my page, which is also connected to my DATASET ( #dataset5 ).
    The REPEATER is showing all of the elements of my database including all DB-Fields.
  4. Also i have 2-elements on my page → IMAGES (or SHAPES) ← (with ID: #image138 and #image139 ). By the way, don’t ask me why i have called them like these, because i do not know how to define and declare elements the right way.

I think, since i am using image-elements, may be i should define the element’S IDs as…
—> “imgOn” <— and —> “imgOFF” <—

To give you a better and more detailed overview i will add some pics to show you my SETUP…

MY-DATABASE:

Here you can see only the first 20-data-entries, but in realtime my database has 2000-items. In this example my DATABASE has the ID —> “DATABASE” (Rentingmembers).
Just used another database for example!

MY-DATASET: Here you can see the SETUP of my DATASET…(in this example it is has the ID —> #dataset1” (dataset5)

MY REPEATER: Here you can see my REPEATER with the ID: #repeater1 (standard ID)

The repeater shows all data from my database. You also can see the IMAGE on the very left side of the REPEATER, which should now show the current state (in this example) —> of my TITLE-FIELD. That means, if inside of my TITLE-FIELD there is some VALUE —> the identifying “IMAGE-ELEMENT” (in this example → “SHAPE-ELEMENT”), should show the correct state of the TITLE .

If title has a VALUE -----> SHOW SHAPE-ELEMENT
If title has no VALUE ---> HIDE SHAPE-ELEMENT

But exactly this is my problem! It does not work and i don’t know how to manage it, to show the current state of each TITLE’s value.

Someone advised me to use → BOOLEAN-FIELDS ← but i want to use the related fields directly.

MY USED IMAGE-ELEMENT:


Just a simple image (in this case a → SHAPE-ELEMENT).
Which should show the current state of each of my items inside my database.

If a title has a VALUE → the shape should show-up!
If there is NO-VALUE inside the title-field ----> the shape should get hidden.

I connected my repeater with my dataset, but i do not know how to get this function, because when i filter my dataset → the whole data which do not hit the seach-criteria, gets hidden, because it is not in the search-results.

I need a way, to show all my results and each of those result-items should show their current TITLE-STATE.

I am now searching for weeks for a simple functionality, maybe because i never have provided such an detailed setup of my project. I have opened several different posts, which made it just even worse. I jumped from one issue into the next, what confused me even more. My worst failure was → TO MIX WIX-DATA with a DATASET.

Maybe now someone can help me?

P.S.
Sorry one more time for generating several post, related to one and the same issue, i see now, it made everything just worse.

  1. https://community.wix.com/velo/forum/coding-with-velo/how-to-query-a-date-field-and-show-with-a-lamp-if-it-isn-t-empty

  2. https://community.wix.com/velo/forum/coding-with-velo/is-it-possible-to-combine-two-databases-in-this-way

  3. https://community.wix.com/velo/forum/coding-with-velo/problems-with-collapse-and-expand

I won’t do it in future.

Reply from Velo-Ninja: Of course → your task should be normaly simple…

Check this code and modify it for your own needs…


//----------- USER-INTERFACE ------------------------------
    let datasetID = "#dataset1";
    let itemsLimit = 50;
    let repID = "#repeater1";
    let myDisplayElement = "#image138"; 
//----------- USER-INTERFACE ------------------------------
    

$w.onReady(()=> {console.log("Page is ready...");
    $w(datasetID).onReady(()=> {console.log("Dataset is ready...");
        $w(datasetID).getItems(0, itemsLimit)
        .then((result) => {console.log(result);
            let items = result.items; console.log("Items: ", items);
            let totalCount = result.totalCount; console.log("Total-Count: ", totalCount);
            let offset = result.offset; console.log("Offset: ", offset);
        } )
        .catch((err)=> {console.log(err);});

        $w(repID).onItemReady(($item, itemData, index)=>{
            console.log(itemData);
            if (itemData.title) {
                $item(myDisplayElement).show();
            }
            else {$item(myDisplayElement).hide();}
        });
    });
});

In this example, i used just one element for showing the state.

You can even delete this part of code…(This was just some additional info (try).

$w(datasetID).getItems(0, itemsLimit)
   .then((result) => {console.log(result);
        let items = result.items; 
        console.log("Items: ", items);
        let totalCount = result.totalCount; 
        console.log("Total-Count: ", totalCount);
        let offset = result.offset; 
        console.log("Offset: ", offset);
     }).catch((err)=> {console.log(err);
});

So all you need is this…

//----------- USER-INTERFACE ------------------------------
    let datasetID = "#dataset1";
    let repID = "#repeater1";
    let myDisplayElement = "#image138"; 
//----------- USER-INTERFACE ------------------------------

$w.onReady(()=> {console.log("Page is ready...");
   $w(datasetID).onReady(()=> {console.log("Dataset is ready...");
      $w(repID).onItemReady(($item, itemData, index)=>{
         console.log(itemData);
         if (itemData.title) {$item(myDisplayElement).show();}
         else {$item(myDisplayElement).hide();}
      });
   });
});

I would say, first step done ! ! !

But why first step? What is the second one ???

Oh, and here you will find a working example (for short timem of period)…

https://velo-ninja.editorx.io/code-ninja/blank-2

Compare the results inside the repeater with the current example DATABASE…

Does the repeater show the correct states of the TITLE-Field ???

Thanks Ninja but I think that I have explained my purpose very well in this case and my main question is this > “Is it possible to combine TWO databases in this way?” In your example above I can only see that you connect with the “Rentingmembers” collection and not with the “Members” collection so I am pretty confused :smirk: How can the system find which member is renting the actual video if you are not implementing that database in the code? Please tell me if I get you wrong and in what way because this is extremely hard for me.

Earlier I tried with a repeater but found it to be even more complicated than just letting each video have it own code so I skipped the repeater and are now using an ordinary container box instead. Yes that demands unecessary much text but it is at least easier to understand for a code-idiot that often struggles in weeks and even months for just one function.

QUESTION: Which relationship has your second database to the —> Rentingmembers <— collection?

You need it because ??? … continue…

Because you want to show user-related data only ?
Is this your concern ?

So one more time → WHAT FOR DO YOU NEED → Members <—
And what is inside the databse? (Screenshot?)

Earlier I tried with a repeater but found it even more complicated than just letting each video have it own code so I skipped the repeater and are now using an ordinary container box instead.

And NOT using a REPEATER → again worst case scenario!
You want to keep your WEBSITE —> DYNAMIC <— don’t you ?

I repeat this question: “How can the system find which member is renting the actual video if you are not implementing that database in the code?”

With the full code in the beginning of this thread I try to combine the two databases but for some reason it doesn´t work. Can you find any faults in it?


Maybe DATABASE-PERMISSIONS ? Just an idea. I did not try it.
But yes this is STEP-2. Your thoughts are right, but even if this do not work.
You do not need the → MEMBERS <— DATABASE.

Look! You have items inside your → Rentingmembers <---- database right?
Every of the item was created by a specific different user, right?
Every user has a → “_ownerID” <—. Each of generated items belongs to a specific user.
That means every item is connected to a specific “_onerID”.

“_ownerID” = “userID” and where do you get the user id from?
Exactly when the user has logged in → he also has gotten an specific ID.
How to get this ID ?
Exactly → i already showed you in the past in one of these numerous posts, how to get it using the new MEMBERS-API.

Once you have this ID you are able to filter for USER-SPECIFIC-ITEMS inside your → Rentingmembers - DATABASE.

The repeater should show only the stuff of the current logged-in-user inside the repeater right?

First you wrote - “You do not need the → MEMBERS <— DATABASE”.

Later you wrote - "How to get this ID ?
Exactly → i already showed you in the past in one of these numerous posts, how to get it using the new MEMBERS-API.

This is confusing to me because MEMBERS-API is “Members” when you have your own custom members collection, right?

To clear things up; All the videos are my own and not other members (they are just renting them). The “Rentingmembers” database does not include any member id´s like with the “Members” collection and that´s why I have to combine the two databases or is this a faulty conclusion?

This is confusing to me because MEMBERS-API is “Members” when you have your own custom members collection, right?

Members-API works in relationship to Wix-Members-APP.

You have installed Wix-Members-APP?
Of course you have, either it wouldn’t be able to logg in or register.
The API already works with your registered members on your site.
And if one of your users has logged in → he automaticaly gets an ID.
You can use the MEMBERS-API to get the ID and some more informations about the current logged-in MEMBER.

For example Velo-Ninja has loggen-in onto your site.
→ Velo-Ninja gets his ID:
→ Velo-Ninja is entering the page where you try to bring your member filter to work.
→ on this page you have a code running which identifies directly onReadyness of the page, if Velo-Ninja is a LOGGED-IN-MEMBER.
→ So if he is → you will recieve all MEMBER-DATA about the logged-in-member as result (including email, _ownerID, roles and badges and so on).

And now ? What did we want to do with the gotten ID ?
You want to use this ID to filter for the right items related to the current logged-in user right?

→ So! → After Velo-Ninja has opened this special page, the code immediately got his ID and all his USER-DATA.
→ The CODE also immediately filtered all items inside your Rentingmembers beloging to —> VELO-NINJA → showing all found results for this specific user inside of a REPEATER.

At the end → Velo-Ninja → can see a list of his rented items.

This way every user can see only his own stuff.

And here we go!!! →

The “Rentingmembers” database does not include any member id´s like with the “Members” collection and that´s why I have to combine the two databases or is this a faulty conclusion?

This is your big failure!!!

You even named your DATABASE as —> “Rentingmembers” but anyway you do not include any member-info into it???

Question: Why you do not include member/owner-ID directly inside of this DATABASE ?

Are you able to show an ecxerpt of your 2 databases? (screenshots) ???
Now i am also confused :rofl::unamused: