2016-11-07 3 views
2

У меня есть схема, как это:как исключить полей типа массив с мангуста

var CitySchema = new Schema({ 
    name: {type : String, required : true}, 
    region: {type: Schema.Types.ObjectId, ref: 'Region', required : true}, 
    images: [{type : Schema.Types.ObjectId, ref: 'Image', select: false}] 
}); 

Когда я запрос на сбор, полевые изображения будут по-прежнему отображаться, даже когда я поставил select: false. Как скрыть поле без использования .select('-images')?

+0

Можете ли вы показать нам запрос на руку? – chridam

+0

'City.find ({}). Sort ('name'). Lean(). Exec (function (err, cities) {console.log (города);});' –

+0

Вы пробовали 'City.find ({}, 'name region'). sort ('name'). lean(). exec (function (err, cities) {console.log (города);}) '? – chridam

ответ

1

Когда вы помещаете select: false, вы говорите, чтобы исключить значения внутри массив images. Вы должны поставить select: false для самого массива images.

Посмотрите на this stackoverflow post.


Применительно к вашему делу:

var CitySchema = new Schema({ 
    name: {type : String, required : true}, 
    region: {type: Schema.Types.ObjectId, ref: 'Region', required : true}, 
    images: { 
     type: [{type : Schema.Types.ObjectId, ref: 'Image', select: false}], 
     select: false, 
    }, 
}); 
+1

nice. благодаря :) –

Смежные вопросы