Answer the question
In order to leave comments, you need to log in
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
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
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question