3

This is my database Structure

{ 
    "_id":"5e4d4d6fc01c0000cc0009bd",
    "UID":"5e30376327050000b3006cde",
    "delevery_charge":25,
    "order_item":[ 
        { 
            "id":"5e2f4a636c630000f20053bc",
            "Name":"XXXXX",
            "info":"5e26098d94500000870044ac",
        }
    ],
    "subtotal":110,
    "status":1,
    "updated_at":"2020-02-19T14:59:59.000Z",
    "created_at":"2020-02-19T14:59:59.000Z"
}

I want to Find data where order_item=>info ID .. Im using Mongo db

$db = Table::where(''Dont Know what to do)->first();

How can I do that ???

Dharman
  • 21,838
  • 18
  • 57
  • 107
Rubel Khan
  • 57
  • 5

3 Answers3

0

Have a look at the $elemMatch documentation in MongoDB

db.orders.find({ "order_item" : { "$elemMatch" : { "info" : "5e26098d94500000870044ac" } } });

Should do the trick.

Community
  • 1
  • 1
jpaljasma
  • 1,422
  • 14
  • 20
0

For Laravel you can use the following query:

$info = "5e26098d94500000870044ac";
$result = Table::where('order_item', 'elemMatch', ['info'=>$info])->get()->first();
Gaurav Kanted
  • 75
  • 1
  • 1
  • 8
-1

I am not sure about mongoDB,but you can use json where clauses.

Laravel also supports querying JSON column types on databases that provide support for JSON column types. Currently, this includes MySQL 5.7 and PostgreSQL. To query a JSON column, use the -> operator:

$result = Table::where('order_item->info', 'SOME VALUE')->get();
Ruben Danielyan
  • 696
  • 3
  • 18