0

Note: I have written an example (SSCCE). That code can be found here.

  1. I have a .csv file like so:

    frame.cap_len
    64 
    60
    ...
    
  2. I need to insert this data into MongoDB database using PHP. So I have a database named Traffic and it contains a collection named frameLengthsCollection. I am using the mongoimport commad to insert the data from the CSV file into this collection.

  3. Then I retrieve this data from the database, and display in an HTML table.

  4. 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:

Screenshot

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.

JBel
  • 329
  • 1
  • 5
  • 19
  • May I ask why it's important that you have an incremental integer instead? If you _really_ need to have one, then a simple Google search will give you a bunch of examples. They might not be in PHP, but you implement the same concept in PHP. – M. Eriksson Nov 24 '17 at 06:19
  • `May I ask why it's important that you have an incremental integer instead?` - for display purposes really! – JBel Nov 24 '17 at 06:36
  • Can't you simply echo an incremented integer while you're outputting the data? If you need the integer to be an actual identifier for the document, then my suggestion about doing some research (just google) still stands. I tried and got a lot of hits. – M. Eriksson Nov 24 '17 at 06:38

0 Answers0