php mongodb如何添加php数组而不创建元素0的子数组

时间:2018-02-24 06:29:27

标签: php mongodb

再次尝试这个,因为我认为我上一篇文章Inserting complex PHP array directly into mongodb提出的问题很少,或者没有提供任何问题;博士...我很难找到任何有关过去的文章。基本知识。

我的数组看起来像:

    [publication] => Array
    (
        [_id] => 100000009
        [title] => title
        [author] => author
    )

我正在使用PHPdriver for mongodb,我直接添加这样的数组:

    $result = $publications->insertOne([
        $publication
    ]);

虽然这有效,但它给了我这个:

{
    "_id" : ObjectId("5a910438834a9c2314006cf6"),
    "0" : {
            "_id" : "100000009",
            "title" : "uf",
            "author" : "author"
    }
}

我如何改为:

{
    "_id" : "100000009",
    "title" : "uf",
    "author" : "author"        
}

无需手动将每一行分成“id”=> insertOne语句中的$ publication ['id']?

0 个答案:

没有答案