M
M
Max Vyznyuk2016-04-12 01:38:15
MongoDB
Max Vyznyuk, 2016-04-12 01:38:15

Links between documents in MongoDB. How to remove pointers?

There are two documents Price and Product.
Their simplified structure:

Price = {
    name: String,
    id: ObjectId,
    products; [ ObjectID ]  // Массив с id товаров которые есть в этом каталоге
}

Product = {
    name: String,
    id: ObjectId,
    relationToPrice: ObjectId // Указатель на документ Price к которому относится товар
}

What is the best way to make the product removal operation as efficient as possible?
So that when a Product is deleted by its id, the same id is removed from the products array in the Price document.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Litvinenko, 2016-04-12
@thespacemax

Why did you separate them? An array with catalog id's could be put into a product, it's not a muscle, after all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question