How to query for nested array in php and laravel using mongoDB

孤人 提交于 2019-12-11 06:56:39

问题


I'm using MongoDB with PHP's own driver and I have saved multiple arrays under main document. Structure looks like this:

[
  {
    _id: 5,
    unique: true,
    name: "Joseph",
    password: "mangalore"
  },
  {
    _id: 9,
    unique: true,
    name: "John",
    password: {
      passcode1: 1,
      passcode2: 2
    }
  }
]

Note: I want to fetch the data where passcode2 > 1

Note: Can u please show me both php and laravel code

My code is

$id = DB::connection('mongodb')
     ->collection('login2')
     ->where(array('password.passcode2','>',2))
     ->get();       

return $id;

来源:https://stackoverflow.com/questions/42383151/how-to-query-for-nested-array-in-php-and-laravel-using-mongodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!