How to push data in nested document in mongodb with laravel

时间:2016-04-04 17:20:34

标签: php mongodb laravel

I am facing an issue while pushing the data in nested document using mongodb and laravel. The collection structure are as follows:

{
  "_id" : ObjectId("56f432f5b720531878f8c935"),
  "test1" : [{
      "Name" : "test",
      "_id" : ObjectId("56f432f5b720531878f85926"),
      "isActive" : 0,
      "test2" : [{
          "Name" : "testing",
          "_id" : ObjectId("56f432f5b720531858f8c965"),
          "isActive" : 0,
          "test3" : [{
              "Name" : "test",
              "_id" : ObjectId("56f432f5b720541858f8c965"),
              "isActive" : 0
            }, {
              "Name" : "test1",
              "_id" : ObjectId("56ffeb9c7ae65b1124000714")
            }]
        }]
    }],
  "created" : ISODate("2012-12-31T18:30:00Z")
}

I tried to solve the issue using aggregator but stood still in finding the index of the nested document. since i can push the data using

test1.0.test2.test3 likewise... in there any way to find the index of the nested document using mongodb alone?

array('$unwind' => '$test1'),
                        array('$unwind' => '$test1._id'),
                        array('$unwind' => '$test1.test2'),
                        array('$unwind' => '$test1.test2._id'),
                        array(
                            '$match' => array(
                                '$and' => array(
                                    array('test1._id' => array('$in' => array('234234234'))),
                                    array('test1.test2._id' => array('$in' => array('456456456'))),
                                )
                            )
                        ),
                        array('$project' => array(
                                'test1' => 1,
                            )),

0 个答案:

没有答案