Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Creation Date and Time #46

Open
aesculus opened this issue Dec 5, 2014 · 0 comments
Open

Document Creation Date and Time #46

aesculus opened this issue Dec 5, 2014 · 0 comments

Comments

@aesculus
Copy link

aesculus commented Dec 5, 2014

It looks like the Save function keeps track of the actual date and time of a save and that is used when the document is merged versus the sequency or _rev? Is that correct?

function save(db, doc) {
  delete(doc._rev); // delete any revision numbers copied from previous docs
  doc.$createdAt = (new Date()).toJSON();
  if (doc.$id) { // update?
    // this format guarantees the docs will be retrieved in order they were created
    doc._id = doc.$id + '_' + doc.$createdAt;
    return db.put(doc).then(function (response) {
      response.$id = doc.$id;
      return response;
    })["catch"](/* istanbul ignore next */ function (err) {
      // It appears there is a bug in pouch that causes a doc conflict even though we are creating a
      // new doc
      if (err.status !== 409) {
        throw err;
      }
    });
  } else { // new
    return db.post(doc).then(function (response) {
      response.$id = response.id;
      return response;
    });
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant