A
A
Alexey2021-01-28 22:39:01
Node.js
Alexey, 2021-01-28 22:39:01

Why doesn't filtering work in ORM Sequelize by operator Op.ne?



Please tell me why filtering users by id might not work

.
The goal is to get all users except the current one.

The code itself:

const Sequelize = require('sequelize')
const Op = Sequelize.Op
const User = require('../model/user.model')

exports.findUsers = async (request, response) => {
    try {
        const name = request.query.name;
        
        const condition = { id: { [Op.ne]: request.userId } };
    
        const data = await User.findAll({where: condition});
        
        response.send(data);
    } catch (e) {
        response.status(500).send({
            message:
               'При получении списка пользователей возникла ошибка'
            });
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Shvedov, 2021-01-29
@mmmaaak

Turn on the logs and see what sql is generated when this query is called.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question