简体   繁体   English

Rest API猫鼬子文档删除与PUT

[英]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. 我们已经实现了将Express与猫鼬结合使用的REST API,我想知道如何在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. 我既可以将它们放在单个PUT合同中,又可以期待一些变量,该变量将让我知道是否正在添加或删除子文档。

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. 或者,我可以将子文档的添加内容放入PUT合同中,并为删除子文档定义一个单独的DELETE合同。

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. 将子文档的逻辑以及父文档嵌入其中还需要做很多工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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