rwynn/monstache

How to keep an embedded document in full sync?

HamzaFudda opened this issue · 0 comments

I want to keep my embedded document also up to dated is there any way from which i can do it. For example I want to keep my price always in sync, if I change the price on product collection it should reflect here.

`[[script]]
namespace = "DB-Dev.posts"
script = """
module.exports = function(post) {
// Check if post is active
if (!post.active) {
return false; // If not active, return false
}

// Enrich 'post.product'
if (post.product) { 
    post.product_details = findId(post.product, {
        select: {
            stock: 1,
            sold: 1,
            discount: 1,
            price: 1,
        },
        database: "DB-Dev",
        collection: "products"
    });
}

// Enrich 'post.category'
if (post.category) { 
    post.category_details = findId(post.category, {
        database: "DB-Dev",
        collection: "categories"
    });
}

return post; // Return the enriched post object

}
"""`

@rwynn