mongoose 查询 find 指定字段

版权声明:转载请评论留言 https://blog.csdn.net/solocao/article/details/82898931

在第二个参数中填写字符串,需要查询的字段用空格相连。

const Person = mongoose.model('Person', yourSchema);
// 查询每个 last name 是 'Ghost' 的 person, select `name` 和 `occupation` 字段
Person.findOne({ 'name.last': 'Ghost' }, 'name occupation');

官方文档 https://cn.mongoosedoc.top/docs/queries.html

猜你喜欢

转载自blog.csdn.net/solocao/article/details/82898931
今日推荐