Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

287
Views
$pullAll in mongoose doens't work

I have this mongoose schema:

// ------- creating active_rooms model -------

var active_rooms_schema = mongoose.Schema({
    room_name: String,
    users: [String]
});
var active_rooms = mongoose.model('active_rooms', active_rooms_schema);

the DB looks like this:

[{"_id":"586b8eeeebb48c65bcbbc5f3","room_name":"my_roome","__v":0,"users":["sam","sally"]}]

pretty strightforward. I have a chat room and people (array of user to that room). I want to remove a certain person once he/she exits the room.

therfore, I wrote this code on my server:

remove_user_from_room: function (user_name, room_name) {
    console.log("remove_user_from_room: " + room_name + ", user: " + user_name);
    active_rooms.update( {'room_name': room_name }, { $pullAll: {'users': [user_name] } } )
},

however, this code doesn't remove a user from the array. it doesn't change the array in my DB.

where is my mistake?

Thanks

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

The problem was of lack sync, I needed to use promises.. the code above is correct.

over 4 years ago · Santiago Trujillo Report

0

Why are you using $pullAll, if you want to remove a single person only. Use $pull

remove_user_from_room: function (user_name, room_name) {
    console.log("remove_user_from_room: " + room_name + ", user: " + user_name);
    active_rooms.update( {'room_name': room_name }, { $pull: {'users': user_name } } )
},
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!