如何从mongodb中的嵌套数组中检索所有记录

时间:2017-03-10 16:40:58

标签: php arrays mongodb laravel eloquent

大家, 我想从mongodb数据库中检索所有具有特定所有者名称的板。我正在使用Laravel

以下是样本数据。

{
        "_id" : ObjectId("58c2e3b853c06144b6038f3e"),
        "name" : "a new board",
        "description" : "fxcb",
        "owner" : {
                "id" : "58bc562553c06113f130bbb3",
                "name" : "Joker"
        },
        "slug" : "a_new_board",
        "updated_at" : ISODate("2017-03-10T17:34:48.628Z"),
        "created_at" : ISODate("2017-03-10T17:34:48.628Z")
}
{
        "_id" : ObjectId("58c3097b53c06144b6038f40"),
        "name" : "Board by Tom Cruise",
        "description" : "afgf",
        "owner" : {
                "id" : "58c3090b53c06144b6038f3f",
                "name" : "Tom Cruise"
        },
        "slug" : "board_by_tom_cruise",
        "updated_at" : ISODate("2017-03-10T20:15:55.132Z"),
        "created_at" : ISODate("2017-03-10T20:15:55.132Z")
}

我尝试了什么:

$boards = Board::where(['owner']['name'],'=', 'Joker');

给出错误

  

未定义的索引:名称

$boards = Board::where(['owner']['name'],'=', 'Joker');  给出错误

  

数组到字符串转换

请帮忙。提前谢谢。

0 个答案:

没有答案