Requirements :
- Basic Knowledge of MongoDB
- MongoDB Server
- PHP driver for MongoDB
Start the server:
1.In windows, go to cmd and navigate to bin folder in mongodb
installation location.
installation location.
2.Execute " mongod " command to start the server.
If you haven't installed mongodb server before.check my videos MongoDB installation in windows and php driver setup for mongodb
code:
Explanation :
$connection=new MongoClient();
MongoClient() by default creats a connection to server at localhost:27017.If you want to create a connection to remote server then you can specify it as arguments.
$db=$connection->university;
This piece of code selects the database named university.If the database haven't created before,mongodb will automaticaly creates a databse.
$student_collection= $db->student;
same as above line,but this line creats (if first time ) and also selects collection(table in RDMS) named student.you dont have to specify any schema ,mongodb has dynamic schema feature.
Finally,create an array with required fields.Insert created array (document) in to collection using insert() function.
Finally,create an array with required fields.Insert created array (document) in to collection using insert() function.