Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Codeigniter中使用MongoDB将子文档更新到数组中?_Php_Mongodb_Codeigniter - Fatal编程技术网

Php 如何在Codeigniter中使用MongoDB将子文档更新到数组中?

Php 如何在Codeigniter中使用MongoDB将子文档更新到数组中?,php,mongodb,codeigniter,Php,Mongodb,Codeigniter,我使用的是Codeigniter 3.0.6,这个MongoDB库 我想做的是用ObjectId(“570f6e08407729ec3000002b”)更新以下委员会的子文档中的字段 但是使用上面的库,或者你能建议我一些其他的方法使它正常工作吗。请不要提及mongodb命令行,因为我知道。所以,如果您能帮助我使用PHP代码,或者codeigniter的话,那就太好了 db.collection.update({“committes.name”:2015},{$set:{committes.$.n

我使用的是Codeigniter 3.0.6,这个MongoDB库

我想做的是用ObjectId(“570f6e08407729ec3000002b”)更新以下委员会的子文档中的字段


但是使用上面的库,或者你能建议我一些其他的方法使它正常工作吗。请不要提及mongodb命令行,因为我知道。所以,如果您能帮助我使用PHP代码,或者codeigniter的话,那就太好了

db.collection.update({“committes.name”:2015},{$set:{committes.$.name:2016}},false,true);请在您想使用的mongodb Completing注释中尝试这段代码,不知道CI lib是否/如何支持它,但使用普通PHP驱动程序是完全可行的。@msvairam在我通过mongod编辑器与mongodb通信时工作正常。但在CI中,它似乎不起作用。因此,我修改了当前的CI mongodb库。这样我就可以为$set函数提供更多的参数。所以现在它工作得很好。
{
"_id" : ObjectId("570f4a94407729d42e00002e"),
"name" : "Test Community",
"committees" : [ 
    {
        "_id" : ObjectId("570f6e08407729ec3000002b"),
        "name" : "2016",
        "start" : ISODate("2016-01-17T00:00:00.000Z"),
        "end" : ISODate("2016-12-12T00:00:00.000Z"),
        "join_state" : 1,
        "state" : 1
    }, 
    {
        "_id" : ObjectId("570f6e08407729ec3000002c"),
        "name" : "2017",
        "start" : ISODate("2017-01-17T00:00:00.000Z"),
        "end" : ISODate("2017-12-12T00:00:00.000Z"),
        "join_state" : 1,
        "state" : 1
    }
]}