为了账号安全,请及时绑定邮箱和手机立即绑定

mongoose如何查找摸个数组里含有某个值?

mongoose如何查找摸个数组里含有某个值?

慕田峪7331174 2018-07-22 08:16:57
例如const ProjectSchema = new mongoose.Schema({name : { type:String },time : { type:Date, default:Date.now },url : { type: String},user : { type: Object},proId : {type: String},spaceId : {type: String},description: {type: String},participant: {type: Array}我需要 通过 传入的id 查找,participant里面含有该id的数据
查看完整描述

1 回答

?
波斯汪

TA贡献1811条经验 获得超4个赞


mongooes我不怎么熟,所以我就写查询语句了
我不知道你的participant内部是什么结构
假如是

participant:[1,2,3]

然后要找id是1,那么查询条件是

{participant:{$elemMatch:{$eq:1}}}

假如是

participant:[{id:1,num:5}]

然后要找id是1,那么查询条件是

{participant:{$elemMatch:{id:1}}}

$elemMatch


查看完整回答
反对 回复 2018-07-23
  • 二师兄e
    二师兄e
    {participant:{$elemMatch:{$eq:1}}} 如果我要查 1and2 呢
  • 1 回答
  • 0 关注
  • 502 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号