我有这样的猫鼬模式:
const userSchema = new Schema( {
email:{ type: String, required: true, unique:true, index:true },
mobile:{ type: String },
phone:{ type: String },
firstname: { type: String },
lastname: { type: String },
profile_pic:{type:String},
socialHandles: {
type: Map,
of: String
},
active: {type:Boolean, default:true}
}, {
timestamps: true
} );
我想查询“给我用户,其中socialHandles.instagram = jondoe”该怎么办?请帮忙
猫鼬的地图成为数据库中的嵌套对象
{ "_id" : ObjectId(""), "socialHandles" : { "instagram": "jondoe" }, ..., "__v" : 0 }
因此您可以使用点符号来查询它:
let user = await User.findOne({ 'socialHandles.instagram': 'jondoe' });
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句