2

There is common use case when you need update or insert. For instance:

 obj = db['data'].find_and_modify(
        {
            'Name': data['Name'],
            'SourcePage': data['SourcePage'],
        },
        data,
        upsert=True
    )

Of course can split this request into GET and then PATCH or INSERT but maybe there is better way?

P.S. eve provides some nice features like document versions and meta data (_created, _updated etc.)

ndmeiri
  • 4,979
  • 12
  • 37
  • 45
alexander_ch
  • 356
  • 5
  • 12

1 Answers1

4

upsert support is now part of the upcoming release.

One doesn't have to do anything different. The feature is "turned on" by default. So if a user tries to PUT an item that does not exist, a new item will be created. The id field sent in the payload is ignored.

If a user does not want this feature, the user needs to explicitly set UPSERT_ON_PUT to False. Now, the user gets the "old" behaviour back. i.e when the user tries to PUT non-existing item, 404 is returned.

Mandar Vaze
  • 1,324
  • 13
  • 20
  • Thanks. I have been trying to find that answer for over an hr. –  Nov 06 '15 at 22:13
  • hey Vaze, even when setting UPSERT_ON_PUT to TRUE, im still getting a 404. what should be the url be when sending a PUT request on an non-existent item? – saad arshad Dec 02 '16 at 13:47