Removing a Firestore Document when the identifier is assigned to a unique name that is not predefined in any location

Presently, my database stores user information. The unique identifier for each document is the user's initial name upon registration, even though this name may have been changed at a later time without updating the document's name.

My dilemma is how to locate a document by name in order to delete it.

I attempted using

"db.collection('Users').where('user_id', '==', this.user.uid)" 

This code is successfully used elsewhere to associate authentication with user profiles, but I am uncertain how to delete the entire document as calling ".delete()" immediately after causes errors.

Does anyone have suggestions or solutions?

Answer №1

It has been clarified after your comment below that this.user.uid is not the id of the Firestore document

Therefore, you will need to execute a query and once you have the query result (using the then() method), delete the specific document returned by the query. Here is an example of how to do this:

var query = db.collection('Users').where('user_id', '==', this.user.uid);

query.get()
.then(function(querySnapshot) {
    var docSnapshot = querySnapshot.docs[0];   
    docSnapshot.ref.delete();
});

You do not necessarily have to utilize a Query for this purpose. Instead, you can directly reference the document (create a DocumentReference) and invoke the delete() method like so.

db.collection('Users').doc(this.user.uid).delete();

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

Is it possible to uncheck a checkbox from a list, even if some of them are already unchecked?

I am attempting to implement a feature where checking a checkbox selects all others in the list, and unchecking one deselects all. Currently, only selecting one checkbox allows me to check all the rest, but unchecking one doesn't trigger the reverse a ...

Toggle the visibility of table rows using checkboxes

I'm working with checkboxes to toggle the visibility of specific rows in a table based on their content matching the selected checkbox values. Checkboxes: <input type='checkbox' name='foo1' value='foo1' v-model="sele ...

Changing the value of a JavaScript variable within the .Net Codebehind

I've run into an issue where I need to update a JavaScript variable after post-back. My initial approach was to use the ClientScript.RegisterStartupScript function, which worked fine during the first page load but failed on subsequent postbacks. I inc ...

Utilizing getJSON to parse data from a hierarchical JSON file for visualization in Google Chart

Need help with adding JSON data to a Google Charts table. Check out the jsfiddle for a quick overview. Having trouble getting the json data added to the table - any suggestions are welcome! Struggling to add multi-level JSON data to a Google Charts Table. ...

What are the steps to confirm form submission with $pristine and $dirty in Angular?

I recently created a form using the resources available at https://github.com/nimbly/angular-formly and . While most of the validation is being handled by Angular, the user-friendliness of the form validation needs improvement. I am looking to implement va ...

Could one harness the power of SO's script for adding color to code within questions?

Similar Question: Syntax highlighting code with Javascript I've observed that Stack Overflow utilizes a script to apply color coding to any code shared in questions and answers, making it resemble how it would appear in an IDE. Is this script pub ...

Obtain the value of an element from a React UI Material component (e.g. ListItemText)

Incorporated an onClick() event where a function is invoked to retrieve and display the value of any clicked element within the HTML body in a web component. <div id="root" onclick="handleClick(event)"></div> This snippet o ...

Is it possible to replace the prototype of an object with a different object?

When an entity is generated, its prototype is established as another entity. Is it possible to alter the prototype of a previously created entity to point to a different object? ...

Solve the problem with SCSS at the component level in NextJS

I've decided to transition my regular React app to Next.js. In the past, I would simply import SCSS files using: import from '.componentName.scss' However, now I need to import them using: import style from 'componentName.module.scss ...

Transform the javascript ES6 class into a functional programming approach

I am interested in converting my reactjs class to a functional programming approach rather than using OOP. Can anyone provide guidance on how to achieve this? Please refer to my code snippet below. import * as h from './hydraulic'; const vertic ...

Only encountering a 401 error with API requests in the production environment

Having an issue where Laravel 6 API requests are functioning smoothly on the local server, but encountering a 401 error on the remote server. Both servers are nginx-driven with php-fpm setup. Authentication is done using Laravel Passport ...

Discover the method to retrieve the chosen value from a list of radio buttons using AngularJS

After making an AJAX request and receiving JSON data, I have created a list of radio buttons with values from the response. Although I have successfully bound the values to the list, I am facing difficulty in retrieving the selected value. Below is a snipp ...

Difficulty encountered while implementing Ajax POST in CodeIgniter

I've been working on a project similar to a ticket system that occasionally requires lengthy answers. When using CKEDITOR in the answer area, the agent's changes are automatically saved to the database using Json GET. However, I encountered an er ...

Enhancing Security: Implementing Node.js API Authentication

Looking for guidance on setting up multiple authentications with different roles in Next.js development. Can anyone help me navigate this aspect of website building? Using Next.js for the frontend Utilizing Node.js and JWT (JSON web token) for the backend ...

methods for transferring information from a website to a smartphone using SMS

I am currently in the early stages of learning JavaScript and working on a project that involves creating a form (a web page) to send data to my mobile device via SMS when the submit button is clicked. However, I am unsure how to transfer data from JavaS ...

Changing $scope within an AngularJS service

I am currently working on an application that utilizes the Gmaps API for geolocalization. One of the challenges I faced was adding new markers based on user events. To address this, I created a service that listens to map events and adds markers when click ...

What is the best way to configure the loading state of my spinner?

When a user clicks to navigate to the articles page, I want to display a spinner while waiting for the articles data to be fetched and displayed. There is a slight delay after the click, hence the need for the spinner. I have a custom spinner component ca ...

Show the current date and time, and update it whenever the user chooses a different one

I need help with displaying the current date and time within a div, with the seconds refreshing when the page loads and changing when the user selects another date and time from the picker. I'm trying to accomplish this with the following script, but ...

Assigning ng-view to "NAME" using RouteProvider

I'm completely new to Angular and I have a question regarding injecting a template or URL into multiple ng-views. However, my current approach involves having ng-view in my base template. My base template structure is as follows: <body> < ...

Matrix calculation for bone orientation towards an object in Three.js

I am encountering issues with calculating the orientation of a bone to "look at" an object. The lookAt function is not functioning as expected for me. This could be due to the fact that the bone's matrix is an identity matrix in local space, so the de ...