Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Solution for Invalid Object ID in MongoDb

    • 0
    • 2
    • 2
    • 1
    • 0
    • 0
    • 0
    • 0
    • 6.33k
    Comment on it

    We usually have this kind of error while making query with mongodb "Uncaught exception 'MongoException' with message 'Invalid object ID'" , the main reason behind this kind of error is that :->

    a) Id string for mongodb must be 24 hexadecimal characters. If an invalid string is passed to this constructor, the constructor will ignore it and create a new id value.

    Thus to solve this kind of error we can try something like this :

    $_id = "-6";
    try {
        $_id = new MongoId($_id);
    } catch (MongoException $ex) {
        $_id = new MongoId();
    } 

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: