express-restify-mongoose icon indicating copy to clipboard operation
express-restify-mongoose copied to clipboard

upsert function (update if exists and insert if doesn’t exists)

Open idrenski opened this issue 8 years ago • 3 comments

Hello, I want to develop upsert (update if exists and insert if doesn’t exists) function with the methods from express-restify-mongoose which works on server side. Any hints are welcome.

In general what is missing to me is documentation by examples.

Thanks in advance.

idrenski avatar Jun 23 '16 06:06 idrenski

When working through an API, you usually know if an object exists or not. Do you have a particular use-case for upsert?

Indeed, we are a bit lacking in examples, this is definitely an area that needs work!

Zertz avatar Jul 08 '16 01:07 Zertz

The use case is when you want to store user settings or user preferences. In most of the cases you simply want to store the actual data and don't care if have been exist or not until that moment. In this case upsert function is most convenient for the developer.

idrenski avatar Jul 08 '16 09:07 idrenski

Fair enough. The best I can offer you at the moment is to create defaults when said user signs up and then you don't have to worry about upserting.

Zertz avatar Jul 12 '16 03:07 Zertz