Coder Social home page Coder Social logo

How check for ObjectId? about runtypes HOT 3 CLOSED

205g0 avatar 205g0 commented on June 2, 2024
How check for ObjectId?

from runtypes.

Comments (3)

yuhr avatar yuhr commented on June 2, 2024

I'm not familiar with MongoDB, but as far as I can tell according to the documentation, it's binary format that you need to parse by yourself, as runtypes doesn't understand binary data.

I don't know what you exactly mean by “check”, but if you want to ensure that a given 12-byte data is truly meant to be ObjectId, the only option would be to ask the sender of the data to wrap the bytes by some tag, like { tag: "ObjectId", payload: "507f1f77bcf86cd799439011" } and test it by Record({ tag: Literal("ObjectId"), payload: String }), since the format is not self-descriptive i.e. it does not contain some kind of “magic bytes” to identify itself is an ObjectId.

from runtypes.

205g0 avatar 205g0 commented on June 2, 2024

Thanks, just checking if instanceof ObjectId would be enough, also I would like to keep it like it is and not transformed to a string

from runtypes.

yuhr avatar yuhr commented on June 2, 2024

Oh sorry, then InstanceOf runtype is exactly what you want. Going to add to the documentation. Thanks!

from runtypes.

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.