These are chat archives for Automattic/mongoose

23rd
Feb 2016
Diego Aguilar Aguilar
@diegoaguilar
Feb 23 2016 06:58
@vkarpov15 I need Schema aditions on the go, like some schemas might get some extra required fields (I can't know which) according to the running app, I've thought maybe something like fixtures might help me
any suggestion?
also, I've thought, as I'm usng config module (https://www.npmjs.com/package/config) maybe I can merge objects into the object within the schema creation
Samuel Marks
@SamuelMarks
Feb 23 2016 09:02
How to specify --authenticationDatabase in mongoose?
antonioaltamura
@antonioaltamura
Feb 23 2016 17:21
This message was deleted
antonioaltamura
@antonioaltamura
Feb 23 2016 17:26

guys I'm trying to do a simple query on an array of embedded docs:

var schema = new Schema{
    name:String,
    registrationNumber:[{ number: Number, year: Number,suffix:Number}],
}

my route

router.get('/', function(req,res) {
    var query = JSON.parse(req.query.q)
    model.find(query, function(err,data){
        if(err) console.log(err)
        res.json(data);
    });

});

my request

/api/model?q={"registrationNumber.number":"1990"}

what am I doing wrong?
Searching around it's possible query an array like this

James Lee
@uptownhr
Feb 23 2016 17:54
it should be, can you show us the output of console.log(query)
antonioaltamura
@antonioaltamura
Feb 23 2016 18:01
console.log(query) -> { 'registrationNumber.number': '1990' }

console.log(req.query.q) -> {"registrationNumber.number":"1990"}

Using JSON.parse(req.query.q) I get an empty array as response
Without JSON.parse I get the whole collection.

maybe the problem is the fields are defined as number?