Database 嵌入关系的特殊位置-Laravel MongoDB

Database 嵌入关系的特殊位置-Laravel MongoDB,database,mongodb,laravel-5,Database,Mongodb,Laravel 5,我有以下用户收藏: { "type": "provider", "name": "user name", "username": "username", "password": "$2y$10$D3z0tLwOwB0tqPEnl63VuexOwqcR75QkVILemB1.TEsAJlk6Ixwim", "specialties": [ "specialty 1", "specialty 2" ] } 和一个特产系列: { "_id": "5

我有以下用户收藏:

{
  "type": "provider",
  "name": "user name",
  "username": "username",
  "password": "$2y$10$D3z0tLwOwB0tqPEnl63VuexOwqcR75QkVILemB1.TEsAJlk6Ixwim",
  "specialties": [
      "specialty 1",
      "specialty 2"
  ]
}
和一个特产系列:

{
  "_id": "5b26103b2df243228c0003ea",
  "title": "specialty 1",
  "description": "specialti 1 desc",
},{
  "_id": "5b26103b2df243228c0003ea",
  "title": "specialty 2",
  "description": "specialti 2 desc",
},
它们之间的关系有很多,这是我在用户模型中的关系

public function specialties()
{
    return $this->embedsMany(Specialty::class, 'specialties', 'title');
}
我想按专业筛选
用户
。例如,如果过滤的专业是“专业1”,则应返回上述JSON用户对象

我知道非嵌入式集合,但我的数据保存在数据库中,无法更改模式


有其他解决方案吗?

解决方案在文档中

就我而言,答案是

$providers = User::where('specialties', 'all', ['specialty 1'])->with('s_specialties')->get();
此代码模拟MongoDB中的
$in
运算符