Skip to content

Getting metadata for operations #106

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

Closed
kbadk opened this issue Jul 28, 2016 · 5 comments
Closed

Getting metadata for operations #106

kbadk opened this issue Jul 28, 2016 · 5 comments

Comments

@kbadk
Copy link

kbadk commented Jul 28, 2016

I recently requested metadata to be included in sharedb-mongo and it was made possible shortly after by adding an options parameter.

However, I'm not quite sure how to actually get the metadata out. The options parameter was added to ShareDbMongo.prototype.getOps:

ShareDbMongo.prototype.getOps = function(collectionName, id, from, to, options, callback) {
  var self = this;
  this._getSnapshotOpLink(collectionName, id, function(err, doc) {
    if (err) return callback(err);
    if (doc) {
      if (isCurrentVersion(doc, from)) {
        return callback(null, []);
      }
      var err = doc && checkDocHasOp(collectionName, id, doc);
      if (err) return callback(err);
    }
    self._getOps(collectionName, id, from, options, function(err, ops) {
      if (err) return callback(err);
      var filtered = filterOps(ops, doc, to);
      var err = checkOpsFrom(collectionName, id, filtered, from);
      if (err) return callback(err);
      callback(null, filtered);
    });
  });
};

But unfortuntaely, the options don't seem to be passed over from ShareDB itself. Backend.prototype.getOps does not take any options parameter and just passes through null as options to sharedb-mongo (through backend.db.getOps):

Backend.prototype.getOps = function(agent, index, id, from, to, callback) {
  var start = Date.now();
  var projection = this.projections[index];
  var collection = (projection) ? projection.target : index;
  var backend = this;
  var request = {
    agent: agent,
    index: index,
    collection: collection,
    id: id,
    from: from,
    to: to
  };
  backend.db.getOps(collection, id, from, to, null, function(err, ops) {
    if (err) return callback(err);
    backend._sanitizeOps(agent, projection, collection, id, ops, function(err) {
      if (err) return callback(err);
      backend.emit('timing', 'getOps', Date.now() - start, request);
      callback(err, ops);
    });
  });
};

How am I supposed to pass options (to get metadata) to sharedb-mongo without modifying the ShareDB source code?

@kbadk
Copy link
Author

kbadk commented Aug 31, 2016

Is this being addressed?

@curran
Copy link
Contributor

curran commented Jul 7, 2017

Can you get them out via a straight up Mongo query?

@kbadk
Copy link
Author

kbadk commented Jul 7, 2017

@curran It's in the database, so sure, I suppose you could. However, when I've needed it, I've just changed L239 in ./lib/backend.js:

backend.db.getOps(collection, id, from, to, null, function(err, ops) {

to

backend.db.getOps(collection, id, from, to, { metadata: 1 }, function(err, ops) {

It gets the job done, but it's quite nasty to modify the library, and something you have to remember to do every time you update sharedb, but since the project is dead now, well...

@curran
Copy link
Contributor

curran commented Jul 7, 2017

@kbadk Oh nice! Thanks for sharing that snippet.

It would be great to add a way of passing the options in through ShareDB. Maybe one more argument can be added to Backend.prototype? So the signature could be:

  • Backend.prototype.getOps = function(agent, index, id, from, to, callback)
  • or Backend.prototype.getOps = function(agent, index, id, from, to, options, callback)

Would you be willing to put together a PR that does something like this?

@nateps Any thoughts on an enhancement like this? Would a PR be welcome? Introducing a change like this would help improve the perception that ShareDB is a dead project, which seems to be quite widespread.

@alecgibson
Copy link
Collaborator

This would be solved by: #215

@kbadk kbadk closed this as completed Feb 10, 2021
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

3 participants