We have 2 apps PHP backend app using MongoClient and frontend Flutter app using realm. When we insert data of arrays with relationship from PHP, there is no data in realm but there is data with object id arrays in Mongo DB.
Imagine we have this realm model in flutter
class Order{
ObjectId id;
late List<OrderProduct> orderProducts;
}
class OrderProduct{
ObjectId id;
String? name;
}
When we insert data from flutter using realm like this
final Order o = Order(ObjectId(),
orderProducts : [
OrderProduct(ObjectId(),name:'p1'),
OrderProduct(ObjectId(),name:'p2'),
],);
realm.add<Order>(o);
When query this order, we can use orderProducts.length
in flutter and get result 2.
But when we insert the same with PHP mongo client like this
$collection->insertOne( [ orderProducts : orderProductsIds, // this is array of bson object id created before creating order ] );
There is a data from mongo db but when we use o.orderProducts
that was inserted from PHP, the length is zero.
Is there anything I missed when inserting the object?