Laravel-MongoDB CRUD

Setup Database

by Remy Pereira on 10th October 2016

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"
 	
  } ]
)

Post a comment

Comments

Nothing yet..be the first to share wisdom.