Hey there. I have a document with two properties, products
and catalog
. When I'm creating catalog
, based on the products
property, I sometimes push one of the products from products
to an array in catalog
. When printing the product's properties right when inserting it, I see everything, the title, price and so on. But when I later query catalog
in the database, all I see is an id referring to product object inside the original document's products
array.
Anyone know what's up with that? I assume it's some kind of optimization on Mongoose's part, to prevent duplication, but in this instance I'm fine with the data being duplicated, since I don't want to query the products
property for each product in the catalog
.
const CustomerSchema = new Schema({
products: [ProductSchema],
catalog: ProductCategorySchema,
});
const ProductSchema = new Schema({
title: String,
category: ProductCategorySchema
});
const ProductCategorySchema = new Schema({
title: String,
products: [new Schema({
title: String,
})]
});
ProductCategorySchema.add({subCategories: [ProductCategorySchema]});
const generatedCatalog = generateCatalog(customer.products);
console.log(generatedCatalog);
customer.catalog = generatedCatalog;
console.log(customer.catalog);