V
V
Vitalij Rudyuk2014-09-25 12:52:55
PHP
Vitalij Rudyuk, 2014-09-25 12:52:55

How to implement this in MongoDB in php?

For example, there is a collection of users who can have many cars, and each car of a particular user can have different parts that are not related to other cars of users. Cars and their parts are not related to each other and will not be related to each other. This is just for example.
Here's how it looks like in the JSON example
{name: Vova,
avto:[
{
name: Lada, detali: [motor, hodovaya, rama]
},
{
name: Zaz, detali: [motor, hodovaya]
}]
}
The question is how to implement this, so that later you can both update and delete parts or cars from the user. I only switch from sql to nosql as needed in one project. If there is already an article somewhere on this issue, poke ...
Already found how to implement this. It turns out that in order to change some detail, you need to pull out completely one document of the collection into a variable and find this detail in it, change and then save this completely changed document?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2014-09-25
@Faradey

Read the little mongo book , in full, it's small.
In your case, you need update - set (Chapter 2 of this book)
In general, maybe the database architecture is not very convenient?
I would make a collection of documents with spare parts standard for cars.
And in the collection with clients, in case they are tuning - their new parts and I would work with them already, adding the id of the car and unique parts.
But I'm not completely sure, because. xs what the task is, maybe this is a terrible example of architecture for the project as a whole

A
Alexander Kubintsev, 2014-09-25
@akubintsev

To be honest, in this example, I did not see the need to go to Monga.
Schemalessness is needed where 100,500 fields in a table would have to be made, of which, say, 10 were filled for each record.

P
Philipp, 2014-09-25
@zoonman

docs.mongodb.org/manual/reference/database-referen...
php.net/manual/en/class.mongodbref.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question