テーブルユーザーデータは以下の通りです。
<事前> <コード> _id:ObjectId("mongodbid"), name:"acdfgf", skills:[ObjectId("skills id"),ObjectId("skill id 2")], created_at:date, updated_at:date今、1回のヒットのIDに基づくスキルデータでユーザーデータを取得する必要があります。
事前にありがとう...
テーブルユーザーデータは以下の通りです。
<事前> <コード> _id:ObjectId("mongodbid"), name:"acdfgf", skills:[ObjectId("skills id"),ObjectId("skill id 2")], created_at:date, updated_at:date今、1回のヒットのIDに基づくスキルデータでユーザーデータを取得する必要があります。
事前にありがとう...
I have a table user data is as follow:
_id:ObjectId("mongodbid"), name:"acdfgf", skills:[ObjectId("skills id"),ObjectId("skill id 2")], created_at:date, updated_at:date
Now I have to get the user data with skills data based on there id in one hit.
Thanks in advance...
</divこれを試して、 User
はあなたのモデル名
[MySQLまたはMariaDBとハイブリッドを使用している場合、MongoDBにアクセスするようにこのモデルを設定する必要があります。
<事前> <コード> User::whereRaw(['skills' => '2'])->get();これがうまくいかなかったかどうか教えてください。
Try this, Consider User
is your model name
[you should have set this model to access the mongoDb if you are using hybrid with mySql or MariaDB]
User::whereRaw(['skills' => '2'])->get();
let me know if this didn't work.
</div答えを見つけてください
<事前> <コード> header()0Please find answer
$m = new MongoDBDriverManager(); $command = new MongoDBDriverCommand([ 'aggregate' => 'mytestusers', 'pipeline' => [ ['$match' => ['name' => 'Pankaj Choudhary']], ['$unwind'=>'$skills'], ['$lookup' => array('from'=>'mytestskills','localField'=>'skills','foreignField'=>'_id','as'=>'sdfg')], ['$unwind'=>'$sdfg'], ['$group'=>array('_id'=>array('_id'=>'$_id','name'=>'$name','email'=>'$email'),'skills'=>array('$push'=>'$skills'),'sdfg'=>array('$push'=>'$sdfg'))], ], 'cursor' => new stdClass, ]); $cursor = $m->executeCommand('targetjob-plus', $command); $result = $cursor->toArray();
</div© 2022 cndgn.com All Rights Reserved. Q&Aハウス 全著作権所有