Skip to content

Regex ProblemΒ #11

@gustavoleitao

Description

@gustavoleitao

The regex filter doesn't work properly. The example in README may not be updated.

My code:

const express = require('express')
const bodyParser= require('body-parser')
const app = express()
const mongoose = require('mongoose')
const actions = require('mongoose-rest-actions')
const mquery = require('express-mquery')

// Configurations
mongoose.plugin(actions)
app.use(express.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(mquery({ limit: 1000, maxLimit: 10000 }));

mongoose.connect('mongodb://localhost:27017/user-db', { useNewUrlParser: true, useUnifiedTopology: true})

//model

const Schema = mongoose.Schema
const Model = mongoose.model

const userSchema = new Schema({
  name: {
    type: String,
    required: true
  }
})
const User = new Model('User', userSchema)

//routes

app.get('/user', async (req, res) =>{

  const options = req.mquery

  User.get(options, (error, result) => {
    if (error){
      res.status(500).send(error)
    }else{
      res.status(202).send(result)
    }
  })

})

app.listen(3000)

The test:

GET /user?query={"name":{"$regex":"/Bo$/"}}

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions