MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

MongoDB:come risolvere DBRef lato client?

Puoi risolverlo con $lookup operatore. Considera la seguente pipeline di aggregazione:

// 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);
});