How to convert SQL to Mongoose query api

Viewed 92

I am interested if the below mention select can be written in a mongoose query API style, for example:

SessionModel.findOne().where({ token: token}).and() ...

or

SessionModel.findOne().where('token').equals(token).and().where('status').nin(['blocked', 'deleted'])

Select Statement:

SELECT * FROM session WHERE token = :token and (status != 'deleted' OR status != 'blocked');

1 Answers
  • token match you already did,
  • status match $nin not in from array ["deleted", "blocked"]
SessionModel.findOne()
  .where('token').equals(token)
  .where('status').nin(["deleted", "blocked"]);

Playground

Related