Laravel-MongoDB CRUD

Setup Database

In this example we are creating a sample library database in MongoDB. Inside this we have a collection called books. Below are few documents from the books collection.

MongoDB is schemaless and Moloquent's schema builder support is limited . Although you may insert the collection into the database using migrations, in this example, we are doing this straight into the database from mongo shell.

db.books.insert(
[ {
	"isbn": 9780060859749,	
	"title": "After Alice: A Novel",
 	"author": "Gregory Maguire",
 	"category": "Fiction"
 	},
 	{
	"isbn": 9781505297409,	
	"title": "Treasure Island",
	"author": "Robert Louis Stevenson",
	"category": "Fiction"
 	},
	{
	"isbn": 9780071808552,	
	"title": "Java: The Complete Reference",
	"author": "Herbert Schildt",
	"category": "Computing"
 	},
	{
	"isbn": 9781909430167,	
	"title": "I Think Therefore I Play",
	"author": "Herbert Schildt",
	"category": "Biography"
 	},
	{
	"isbn": 9780553380163,	
	"title": "A Brief History of Time",
	"author": "Stephen Hawking",
	"category": "Cosmology"
 	},
 	{
 	"isbn": 9780340951699,	
 	"title": "Mad, Bad and Dangerous to Know",
 	"author": "Ranulph Fiennes",
 	"category": "Geography"
 	},
	{
	"isbn": 9781615193585,	
	"title": "How to Read Water: Clues and Patterns from Puddles to the Sea",
	"author": "Tristan Gooley",
	"category": "Oceanography"
 	},
	{
	"isbn": 9781615193585,	
	"title": "Learning Robotics using Python",
	"author": "Lentin Joseph",
	"category": "Computing"
 	
  } ]
)
Last Updated: 10-October-2016


Post a comment

Name

Your Comment

Email (We dont publish it)

Comments

Remy Pereira | November 15, 2016 4:34 PM |

The Moloquent package supports schema builder. The article has been updated with information about how to make migrations for MongoDB database using laravel-mongodb package. MongoDB Migration

Misheck Munthali | November 15, 2016 4:36 PM |

Hi, your tutorial is really helpful considering there is not much help for this package but how do I insert the collection into the database using migrations.