Note: I have written an example (SSCCE). That code can be found here.
I have a
.csv
file like so:frame.cap_len 64 60 ...
I need to insert this data into MongoDB database using PHP. So I have a database named
Traffic
and it contains a collection namedframeLengthsCollection
. I am using themongoimport
commad to insert the data from the CSV file into this collection.Then I retrieve this data from the database, and display in an HTML table.
Then when I print each member of the cursor returned, I get something like
0>>> MongoDB\Model\BSONDocument Object ( [storage:ArrayObject:private] => Array ( [_id] => MongoDB\BSON\ObjectId Object ( [oid] => 5a17adbbe838ea37cd31f2f2 ) [frame.cap_len] => 64 ) ) 1>>> MongoDB\Model\BSONDocument Object ( [storage:ArrayObject:private] => Array ( [_id] => MongoDB\BSON\ObjectId Object ( [oid] => 5a17adbbe838ea37cd31f2f3 ) [frame.cap_len] => 60 ) ) ...
This is a screenshot of the HTML table:
My Question is that, instead of the contents of the _id
column automatically added, which is something like Array ( [$oid] => 5a17adbbe838ea37cd31f2f2 )
, I need an id
column with simple sequential INTEGER id's (starting with 1 and then autoincrementing).
That used to automatically happen when I used AUTOINCREMENT ID's in MYSQL database. I don't know how to achieve this in PHP-MongoDB?
NOTE: I am using PHP MongoDB driver with the PHPLib library.