Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to keep an embedded document in full sync? #716

Open
HamzaFudda opened this issue Apr 8, 2024 · 0 comments
Open

How to keep an embedded document in full sync? #716

HamzaFudda opened this issue Apr 8, 2024 · 0 comments

Comments

@HamzaFudda
Copy link

HamzaFudda commented Apr 8, 2024

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

@HamzaFudda HamzaFudda changed the title How to keep an embedded document in full sync How to keep an embedded document in full sync? Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant