sql >> Base de Datos >  >> NoSQL >> MongoDB

MongoDB:¿Cómo resolver DBRef en el lado del cliente?

Puede resolver esto con $lookup operador. Considere la siguiente canalización de agregación:

// Execute aggregate, notice the pipeline is expressed as an Array
collection.aggregate([
    {
        "$lookup": {
            "from": "product",
            "localField": "content.product.$id",
            "foreignField": "_id",
            "as": "products"
        }
    },
    {
        "$lookup": {
            "from": "clients",
            "localField": "content.client.$id",
            "foreignField": "_id",
            "as": "clients"
        }
    },
  ], function(err, result) {
    console.log(result);
});