Giter Site home page Giter Site logo

Comments (7)

mjancarik avatar mjancarik commented on July 19, 2024

I found http://mongodb.github.io/node-mongodb-native/api-bson-generated/objectid.html

from bson-objectid.

niftylettuce avatar niftylettuce commented on July 19, 2024

Can you submit a PR to fix this?

from bson-objectid.

niftylettuce avatar niftylettuce commented on July 19, 2024

The PR #46 broke all tests. I am going to revert it in the interim.

I also noticed we need to merge this 418sec#2.

from bson-objectid.

supersime avatar supersime commented on July 19, 2024

Hey there @niftylettuce I have a suggested resolution to this based on how the mongoose library has tackled this. They created a new method to address the issue, so they now have:

  • isValidObjectId: Returns true if Mongoose can cast the given value to an ObjectId, or false otherwise.
  • isObjectIdOrHexString Returns true if the given value is a Mongoose ObjectId (using instanceof) or if the given value is a 24 character hex string, which is the most commonly used string representation of an ObjectId.

Here is a great write-up on the issues they encountered: Automattic/mongoose#11419

Thanks!

from bson-objectid.

titanism avatar titanism commented on July 19, 2024

@supersime it also seems that Mongoose will return true when it's an IP address, such as 192.168.1.20

from bson-objectid.

titanism avatar titanism commented on July 19, 2024
> require('bson-objectid').isValid('192.168.1.20')
true
> require('mongoose').Types.ObjectId.isValid('192.168.1.20')
true

from bson-objectid.

titanism avatar titanism commented on July 19, 2024

We should probably update this repo to use the approach with hex string and 24 char length as per isObjectIdOrHexString

from bson-objectid.

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.