Thursday, February 14, 2013

PHP, Heroku, MongoDB

MongoDB is a key value store. Its built for high-performance and is schemafree. It is also a document oriented database and a relational store. Hence it supports NOSQL (Not Only SQL). It's used by GitHub and sourceforge. You can try it yourself at http://try.mongodb.org/ And you can use it in most languages such as C, C++, C#, php, python, node.js, HASKELL, SCALA,  Java etc. It uses the terms similar to other databases. you type show dbs, use admin, show collections etc.  A collection is a table. Each document is a row.  You can type
db.accounts.find().forEach(function(doc) { print (tojson(doc));});
You can display each document in JSON format this way.  The database is also easy to understand with similar functionality.
Query
You use dynamic queries. You can insert JSON like
db.colors.insert({name:'red', primary:'true'})
> var cursor = db.colors.find()
> cursors.next()
and of course SELECT * from colors where name = 'green'
or db.colors.find({primary: true}).sort({name: 1}).limit(1)
db.people.find({age: {lte:27}})
Operators
You can also use $gt, $lt, $ne, $in, $nin, $mod, $all, $size, $exists, $type, $elemMatch, $not and $where.
Index
You can also use Indexes. db.colors.ensureIndex({name: 1}) for single ascending or -1 for single descending order or {unique:true} for unique and {background:true} for non-blocking index in background
You can also mix with db.colors.ensureIndex({name: 1}, created_at: -1})
Aggregation:
You can use db.colors.distinct('name')
You can also use items group
db.items.group({key:{template:true}, initial:{count:0}, reduce:function(obj, prev) { prev.count += 1}});
Data Types:
Array, Binary, Boolean, DateTime, DB reference, Embedded object, Integer, Null, ObjectId, RegExp, String, Symbol, Timestamp
Relationships are used similarly normalized, embedded ( Embedding is pre-joining) etc. Embed when documents appears with parent. 4MB document size limit.
And there's support via e-mail, IRC, Web, book, conference and training.
reference : slides from jnunemaker

PHP:
web programming language, runs on the web server, It's free, cross-platform interpreted language and is targeted towards web programming. The PHP interpreter runs the command between php tags, string syntax called a here document, displaying information about a database. PHP form runs the command between <?php? > tags and processes form data via $_POST.
PHP worsks on pieces of text called strings. Strings can be of three types - enclosed in single quotes, enclosed in double quotes and a here document. Strings can even contain binary files such as image or sound. Strings can support variable interpolation i.e. the variables in double quotes will be substituted with their value.  Concatenation is called implode and splitting is called explode, randomly shuffle with str_shuffle().  Perl like variables beginning with $.
 Pass by reference and value are both allowed.

No comments:

Post a Comment