The process of connecting a user from a firestore database

Currently, I am working on developing a posting platform using Vue and Firebase. When a user creates a post, their username will be showcased alongside the post. An example would be:

Created by user1

Everything is functioning smoothly in this aspect.

Now, my focus lies on building a user profile page where users can view the name and email of the creator.

The issue I'm facing is that the email and name are not being displayed as intended.

This snippet represents part of the PostDetails page:

<router-link :to="{ name: 'UserDetails', params: { userId: playlist.userId } }" class="username">
    Created by {{ playlist.userName }}
</router-link>

UserDetails page:

<template>
  <div>{{ user.displayName }}</div>
</template>

<script>
import getDocument from "@/composables/getDocument";

export default {
  props: ["userId"],
  setup(props) {
      
    const { error, document } = getDocument("users", props.userId);
    const userName = document.value.displayName
    return {
      error,
      userName,
    };
  },
};
</script>

<style></style>

To check out the website itself, feel free to visit: Website

Furthermore, here is what the database structure looks like:

  1. posts https://i.sstatic.net/Gu3OZ.png

  2. users https://i.sstatic.net/xQRIj.png

Summary


My objective is to enable users to click on a username within a post, navigate to the userDetails page, and view both the user's name and email associated with that specific post. The link functionality has already been implemented successfully.

Answer №1

In the world of NoSQL, one common strategy is to optimize data by denormalizing it in order to retrieve all necessary information for a specific application screen with just one query. Instead of linking separate records as you would in SQL using joins, in this approach all relevant data is stored within the same record for easy display.

For example, each Playlist document could contain duplicated information from its author such as their username and email address.

An important consideration with this method is ensuring that the duplicated values remain consistent and up-to-date across both the User document and the Playlists documents. This synchronization process can be implemented through a Cloud Function triggered whenever the User document is modified.

Embracing data duplication and denormalization in your data model can lead to more efficient querying and simplified access to information. Check out this insightful post on NoSQL data modeling techniques for more information.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a responsive dropdown submenu with Bootstrap 4, utilizing HTML, CSS, and jQuery

My HTML code includes CSS, jQuery Bootstrap 4 elements. I am attempting to add a dropdown submenu to my main menu when hovering over it. However, I am facing issues in getting the dropdown submenu to work properly. When I hover over main menu items like Co ...

Is it possible for third party packages to function properly without the node_modules directory?

Whenever we push our code to GitHub or any other remote repository service, we make sure to exclude the node_modules folder. This begs the question: how are all the third-party libraries functioning on the hosted website if the node_modules folder is not ...

Could you please explain the distinctions among onLoad, onDomready, No wrap - in <head>, and No wrap - in <body>?

When it comes to editing my code, I rely on JSFiddle. However, I have noticed that in certain instances when running JavaScript or jQuery, the code only works if I choose "No wrap - <head>" or "No wrap - <body>". CLICK HERE FOR THE JSFIDDLE EX ...

Creating a legitimate Angular 6 form模shape

I want to reset my form using the following method: public static resetDescriptionFields(i: any, component: any) { var formItems = component.form.get('items') as FormArray; var descriptionItem = formItems.controls[i].g ...

How can I integrate Apple remote support into a website with the use of Javascript?

One thing that I find interesting is the ability to use the Apple remote with Front Row, as well as other apps on Mac that support it. I'm curious about whether Web Apps could also be made compatible through Javascript. I have a concept for a TV-like ...

Encountered a problem while trying to upload a file using node

Hi there! I seem to be facing an issue with the code snippet below. Every time I attempt to upload a file, the browser keeps loading indefinitely. Any thoughts on what might be causing this problem? app.js var formidable = require('formidable') ...

Notification system for managing recurring tasks

Situation I am currently working on an application where users are assigned daily tasks such as "wash the window, clean the floor," and so on. Each task has a specific recurrence interval and must be completed at least once within that time frame. For e ...

Setting the rotation position in JQuery prior to initiating the animation

Perhaps I could phrase my query differently as How can I rotate an image in JQuery from a starting position other than 0 degrees. I am attempting to animate the rotation of an image from -50deg to 0deg. However, regardless of what I do, JQuery seems to al ...

Initiate a project and organize by using mongoose to sort array fields

My mongoose model for a post on a social networking platform is called PostModel: { caption: String, likes: [] // array to store information about users who liked the video, essentially referencing another model comments: [] // array to hold comment object ...

Utilizing a Dependency Injection container effectively

I am venturing into the world of creating a Node.js backend for the first time after previously working with ASP.NET Core. I am interested in utilizing a DI Container and incorporating controllers into my project. In ASP.NET Core, a new instance of the c ...

Pass data from controller using Ajax in CodeIgniter

Here is my JavaScript code: $(document).ready(function(){ $("input[type='checkbox']").change(function(){ var menu_id = this.value; if(this.checked) var statusvalue = "On"; else var statusvalue = "Off"; $.ajax( ...

Calculating minutes per hour during a specific date range using JavaScript

What is the method to create an array representing minute counts per hour within a specified date range? If we have the following dates: const initial = new Date('2019-04-04 12:14'); const final = new Date('2019-04-04 16:21'); How ca ...

Ways to modify the values of a Bootstrap Dropdown using a unique identifier

Here is an example of a typical Bootstrap Dropdown: <div class="btn-group"> <button type="button" class="btn btn-lg btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Default option<span class ...

Transferring Composite Data Structures from JavaScript to a WCF RESTful Service

Below are the code snippets: 1. The intricate object: [DataContract] public class NewUser { [DataMember(Name = "Email")] public string Email { get; set; } [DataMember(Name = "FirstName")] public string FirstName { get; set; } [DataMem ...

utilizing spring mvc conditions to dynamically populate parameters in a javascript URL function

In my Spring MVC application, I have implemented a JavaScript calendar control that redirects the user to a detail page for a selected date. However, I am facing an issue where I need to include additional parameters in the URL along with the date. How can ...

The onhashchange function is limited in its ability to completely track changes in the hash

I set up an onhashchange event listener on the page in the following way: window.addEventListener('hashchange', () => console.log('hash change!')) This listener can detect hash changes that I manually enter: However, I am not see ...

jQuery still not running despite using .ready

I have been attempting to run some jQuery code on my HTML page. After doing some research, I learned that using .ready may be necessary to ensure the DOM is fully loaded before executing the script. Despite this, I am still having trouble getting the scrip ...

Strategies for utilizing dynamic IDs across various components in React

I have a modal component within my React project folder. Its purpose is to extract the ID passed when a user sends a document to Firestore. My goal is to utilize this specific ID in another component when editing the document. Here's an illustrative ...

Switch between classes based on the query using the Ajax response

In order to retrieve data from a database and determine if the field "is_recurring" is set to 1 or 0, I am utilizing an ajax call to my functions.php file. This value is based on a selection made in a dropdown menu. Depending on the result returned by the ...

Set a default value for a FormControl within react-bootstrap

When working with my email address, I utilized the <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="44362125273069262b2b30373036253404746a76706a71">[email protected]</a>. In order to specify the initial value chosen ...