第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Mongoose.js:查找所有喜歡 Cat 帖子的用戶

Mongoose.js:查找所有喜歡 Cat 帖子的用戶

絕地無雙 2022-06-09 16:18:37
我有兩個模式模型。const catSchema = new mongoose.Schema({  name: 'string',  likes: [    {      type: mongoose.Schema.Types.ObjectId,       ref: 'User',      require: true    }  ],});和const userSchema = new mongoose.Schema({  email: {    type: String,    required: true,    unique: true,  },});假設 Cat 集合中有 10 個 Cat 文檔。一位用戶喜歡兩個 Cat 文檔。我想要做的是我想通過Cat模型找到用戶喜歡的兩個貓列表。
查看完整描述

1 回答

?
泛舟湖上清波郎朗

TA貢獻1818條經驗 獲得超3個贊

您可以使用$in來自 MongoDB 的查詢來實現此目的。詳細信息:https ://docs.mongodb.com/manual/reference/operator/query/in/


從文檔中: $in 運算符選擇字段值等于指定數組中的任何值的文檔。


我曾經用它來獲取用戶所屬的組。在您的情況下,您應該成功完成以下操作:



const Cat = require('./models/Cat');

Cat.find({ likes : { $in : [user] }}).exec((cats) => {

  console.log(cats);

});


// user in this case should be the user document

// the query checks if the user is included in the 'likes' arrady


查看完整回答
反對 回復 2022-06-09
  • 1 回答
  • 0 關注
  • 112 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號