@jlrdw
Thanks for the help, but I still don't understand, in the post you sent there is this link: https://zappysys.com/blog/ssis-loading-data-into-mongodb-upsert-update-delete-insert/
but it didn't help me understand my situation very well.
In short, I need to know if a mongodb relationship with laravel has better performance with an objectId() key or just with a string.
In short, for each blog article, I have an author, and within the "Article" model I have the author_id:
{
"_id": ObjectId("5ff7fcf93e2c5a4462b1e619"),
"text": "This is a comment.",
"autor_id": ObjectId("5ff7fbc93e2c5a4462b1e612")
}
and I consult it like this in Laravel:
my Controller:
$check = Artigo::where('_id', '5ff7fcf93e2c5a4462b1e619')->first();
My model:
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use MongoDB\Laravel\Eloquent\Model;
use MongoDB\Laravel\Relations\HasOne;
class Artigo extends Model
{
use HasFactory;
protected $connection = 'mongodb';
public function redator(): HasOne
{
return $this->hasOne(Autor::class, '_id', 'autor_id');
}
}
get autor:
$teste = Artigo::where('_id', '5ff7fcf93e2c5a4462b1e619')->first();
dd($teste->redator->autor)