-2

I want to insert json array elements like below using MongoDB and CodeIgniter.

"ticket" : [
     {
     "problem" : "testing",
     "time_taken" : "5 hrs",
     "number_of_visits" : "7",
     "expenses" : {
             "amount" : "2000",
             "distance_travelled" : "4 km"
              }
     },
     {
     "problem" : "testing",
     "time_taken" : "5 hrs",
     "number_of_visits" : "4",
     "expenses" : {
             "amount" : "2500",
             "distance_travelled" : "5 km"
              }
     }
]

What is the query I have to use for this?

Uma
  • 109
  • 1
  • 1
  • 10

2 Answers2

1

What you need is the Bulk Write functions (https://docs.mongodb.com/manual/core/bulk-write-operations/)

The PHP depends on which library you are using (old or new, hopefully the new one!) but in plain English you:

  • create an array of operations (in your case "inserts")
  • call bulk write.
Robbie
  • 17,605
  • 4
  • 35
  • 72
  • Well, you've obviously done something wrong, but I'm afraid my crystal ball isn't showing me what you've done. So not really in a position to help... – Robbie Jan 23 '17 at 10:16
0

$this->mongo_db->where('_id', new MongoId($id))->push("ticket",$data)->update('engineer');

This is the query I'm using for inserting multiple array values in mongodb codeigniter.

Uma
  • 109
  • 1
  • 1
  • 10