Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

295
Vistas
$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 Respuestas
Responde la pregunta

0

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

over 4 years ago · Santiago Trujillo Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda