如何用mongoose排除数组types的字段
我有这样的架构:
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')
?
当你把select: false
,你说要排除images
数组内的值。 你需要把select: false
为images
数组本身。
看看这个stackoverflowpost 。
适用于你的情况 :
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, }, });
- 我应该如何使用node.js在mongoose / mongdb中存储喜欢/不喜欢和评分
- MongoDB / ExpressJS – 当ObjectID包含在variables中时,通过_id删除文档
- 在ExpressJS上使用mongoose运行“node_acl”
- 无法连接到mongolab,正在获取MongoError:auth失败
- 如何在mongoose中find最新的子文档
- Mongoose / MongoDB batchSize(30)仍然返回所有结果
- 为什么不在db.collection()中callback?find()。toArray(callback)在数据库连接被删除的情况下调用?
- 做多个MongoDB操作的正确方法
- node.js中d3和mongo之间的冲突