简体   繁体   中英

Rest API Mongoose Subdocument Delete vs PUT

We have implemented a REST API using express with mongoose, and I wanted to know how one should implement the addition/removal of subdocuments in a rest api.

I can either put both of these in a single PUT contract and expect some variable which will let me know whether the subdocument is being added or removed.

Or I can put the addition of the subdocument in the PUT contract, and define a separate DELETE contract for the removal of the subdocument.

However, I could not find any documentation on which is the preferred method, or if there is another method of doing this altogether ?

For anyone that may be interested. After testing different approaches, we found for our purposed, that keeping the addition and removal of subdocuments separate was much more easier to achieve and test. Embedding the logic for the subdocument, along with the parent document was much more work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM