What you mean is that if the user changes his avatar, he needs to change the user’s avatar in the post as well
The model you mentioned above does not feel suitable for this scenario; it is better to save the user ID in the post and the user ID in the comments, so that you don’t need to change the information of one user, and you need to modify the corresponding information in multiple places, of course. This method requires you to obtain user information when querying comments information, for example, and you need to make your own choices
If updated,
db.posts.update({userId:'xxxxxx'},{$set:{"head" : "/images/portrait-1490968786371.jpg"}})//Similar to this
Mongodb is not a relational database. It cannot be done with a single SQL statement. It can only be done with nested queries. For people who are used to using relational databases, it is simply impossible to see directly. And seeing that bunch of if (err) { mongodb.close(); callback(err);} makes me even more crazy
Isn’t it better to seek help from others than to seek help from yourself? Finally solved it Posted it for everyone’s reference
What you mean is that if the user changes his avatar, he needs to change the user’s avatar in the post as well
The model you mentioned above does not feel suitable for this scenario; it is better to save the user ID in the post and the user ID in the comments, so that you don’t need to change the information of one user, and you need to modify the corresponding information in multiple places, of course. This method requires you to obtain user information when querying comments information, for example, and you need to make your own choices
If updated,
db.posts.update({userId:'xxxxxx'},{$set:{"head" : "/images/portrait-1490968786371.jpg"}})//Similar to this
Mongodb is not a relational database. It cannot be done with a single SQL statement. It can only be done with nested queries. For people who are used to using relational databases, it is simply impossible to see directly. And seeing that bunch of if (err) { mongodb.close(); callback(err);} makes me even more crazy