Skip to content

How to the value of _id field? #198

ejzhang opened this Issue Jan 7, 2016 · 3 comments

3 participants

ejzhang commented Jan 7, 2016

I use $.post method of jQuery to send a request and received the response, but the _id is empty like screen capture. How i get the value of _id or convert ObjectId to it's value in MongoDB? Thanks very much!
btw: How i format fields in MongoDB? e.g. format '20150901180116' to '2015-09-01 18:01:16'.

ZorgUK commented Jan 8, 2016

It has a __toString() method, just cast it as a string by putting (string) before the variable.

ejzhang commented Jan 8, 2016

Thank you for your reply first!
But how i to do? I try it like bellow, and have nothing.

$query = new MongoDB \ Driver \ Query (
        'FPRXM' => 'XXXXX'
        'projection' => array(
            '_id' => 0,
            'Id' => '$_id.toString()'
ejzhang commented Jan 9, 2016

I convert it to string after got cursor.

foreach ( $cursor as $v ) {
    $v->_id = (string)$v->_id;
@jmikola jmikola closed this Feb 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.