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.48k
    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 :

    1. $_id = "-6";
    2. try {
    3. $_id = new MongoId($_id);
    4. } catch (MongoException $ex) {
    5. $_id = new MongoId();
    6. }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: