Bystander001
Bystander001

Reputation: 121

How do I remove a user in mongoDB from the terminal by username?

My question is this: How can I remove a user from the users db by username, or at all even?

I have a meteor application with a custom registration, and when an account is created you can login and manage your account and what have you.. My problem is that, on the local host for testing, I created a few extra user accounts that I want to delete individually (not a complete reset). I am on OS X so I went to terminal, typed in 'show dbs' but users came up empty and when I typed 'show users' nothing came up. If I type 'db.users.findOne()' information appears and I can get a username and _id. I know there is users and this command shows that there is at least one but the rest of the commands indicate that I can't manage them.

Below is some code for the registration page, specifically the Accounts.createUser I'm not sure it will mater for the response but I wanted to be thorough.

Template.SignUp.events({
    'submit form': function(event, template){
     event.preventDefault();
     var UsernameVar = template.find('#username').value;
     var emailVar = template.find('#Email').value;
     var passwordVar = template.find('#password').value;
     var ConfirmPasswordVar = template.find('#Cpassword').value;
     if(ConfirmPasswordVar == passwordVar)
     {
       document.getElementById("NotValid").style.display = 'none';
       Accounts.createUser({
         username: UsernameVar,
         email: emailVar,
         password: passwordVar
       }, function(err, result){
         if(err)
         {
           document.getElementById("Unavailable").style.display = 'block';
         }
         else{
           document.getElementById("Unavailable").style.display = 'none';
         }
       });
     }
     else{
       document.getElementById("NotValid").style.display = 'block';
     }
   }
 });

I've done a lot of searching on this issue and all I've found is how to grant users the right to remove profiles but I want to do it from terminal, even when the application launches I will be the only one to be using this feature so I don't want to start giving those rights to users.

If there is anything else I should provide please let me know.

Upvotes: 1

Views: 4828

Answers (1)

Adnan Y
Adnan Y

Reputation: 3240

meteor mongo
db.users.find({username: "someusername"}) // ensure that your query returns the correct user that you want to remove
db.users.remove({username: "someusername"})

Upvotes: 2

Related Questions