pouchdb / upsert

PouchDB plugin for upsert() and putIfNotExists() functions
Apache License 2.0
149 stars 25 forks source link

db.upsert diff function returns w/ `_rev` property #2

Closed notslang closed 9 years ago

notslang commented 9 years ago

I find this rather odd because having a diff function eliminates the need for comparison based on revisions, and the upsertInner function handles setting the _rev for you. Could we get rid of that _the _rev property in the supplied document_, so I don't need to delete it, or is there a use-case for keeping it?

db.upsert(post._id, (oldPost) ->
  delete oldPost._rev # would screw up the _.isEqual
  if _.isEqual(oldPost, post)
    console.log post._id, 'skipped'
    return false
  else
    console.log post._id, 'updated'
    return post
)
nolanlawson commented 9 years ago

I don't really understand your question. Do you want the diffFun to be passed a document that doesn't contain the _rev? Or what do you mean?

notslang commented 9 years ago

Do you want the diffFun to be passed a document that doesn't contain the _rev?

yes, exactly.

nolanlawson commented 9 years ago

But what about the _id? Or the _attachments? Or _deleted? It's not really clear what to do about those. Also, it's not really clear what to do with first-generation documents (i.e. the doc doesn't exist yet) vs n+1th-generation documents (i.e the doc and rev both already exist).

I kinda feel like your approach is pretty reasonable. Get rid of the _rev, then compare. Although shouldn't you get rid of the _rev in both the oldPost and the post?

nolanlawson commented 9 years ago

Closing for reasons described in https://github.com/pouchdb/upsert/pull/3