Code Monkey home page Code Monkey logo

Comments (5)

raix avatar raix commented on June 3, 2024

Does DRAFTS.findOne('58d887874e0ca825443236cf') work as expected?

from ground-db.

CyberCyclone avatar CyberCyclone commented on June 3, 2024

No, it behaves the same way that {_id:"58d887874e0ca825443236cf"} is. If the id is not 24 characters, then it works as expected. It's only when there are 24 characters where it fails.

from ground-db.

Chun-Yang avatar Chun-Yang commented on June 3, 2024

The problem is in the MongoID package, idStringify added '-' before the id when fetching the document. LINE 64

MongoID.idStringify = function (id) {                                                                 // 56
  if (id instanceof MongoID.ObjectID) {                                                               // 57
    return id.valueOf();                                                                              // 58
  } else if (typeof id === 'string') {                                                                // 59
    if (id === "") {                                                                                  // 60
      return id;                                                                                      // 61
    } else if (id.substr(0, 1) === "-" || // escape previously dashed strings                         // 62
               id.substr(0, 1) === "~" || // escape escaped numbers, true, false                      // 63
               MongoID._looksLikeObjectID(id) || // escape object-id-form strings                     // 64
               id.substr(0, 1) === '{') { // escape object-form strings, for maybe implementing later
      return "-" + id;                                                                                // 66
    } else {                                                                                          // 67
      return id; // other strings go through unchanged.                                               // 68
    }                                                                                                 // 69
  } else if (id === undefined) {                                                                      // 70
    return '-';                                                                                       // 71
  } else if (typeof id === 'object' && id !== null) {                                                 // 72
    throw new Error("Meteor does not currently support objects other than ObjectID as ids");          // 73
  } else { // Numbers, true, false, null                                                              // 74
    return "~" + JSON.stringify(id);                                                                  // 75
  }                                                                                                   // 76
}; 

Meteor Minimongo works fine since it stores the ids with '-' prefix, but not for ground db.

from ground-db.

Chun-Yang avatar Chun-Yang commented on June 3, 2024

It seems we should not use the custom strid, we should use MongoID.idStringify instead.
https://github.com/GroundMeteor/db/blob/grounddb-caching-2016/lib/client/ground.db.js#L40

from ground-db.

lucfranken avatar lucfranken commented on June 3, 2024

@Chun-Yang did you ever find a solution for this issue? We encounter the same with id's generated by:

new Meteor.Collection.ObjectID()._str

for example an ID:

8298e2f637a1a4b9e114abe8

24 characters it is.

If the issue is not resolvable it would be good to throw an error when an unrecognized ID type is sent into find() and findOne() methods. That way you understand as a developer that this is an ID issue and not a synchronization / data issue.

from ground-db.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.