SQL Statement | Mongo Statement |
mysql_connect('localhost', 'mysql_user', 'mysql_password'); | >New mongo(); |
CREATE DATABASE TEST | >new Mongo("{$host}", array("replicaSet" => true,"slaveOK" => true)); |
CREATE TABLE USERS (a Number, b Number) | use mydb |
ALTER TABLE users ADD ... | db.createCollection("mycoll") |
INSERT INTO USERS VALUES(3,5) | implicit |
SELECT a,b FROM users | db.users.insert({a:3,b:5}) |
SELECT * FROM users | |
SELECT * FROM users WHERE age=33 | db.users.find({}, {a:1,b:1}) |
SELECT a,b FROM users WHERE age=33 | db.users.find() |
SELECT * FROM users WHERE age=33 ORDER BY name | db.users.find({age:33}) |
SELECT * FROM users WHERE age>33 | db.users.find({age:33}, {a:1,b:1}) |
SELECT * FROM users WHERE age!=33 | db.users.find({age:33}).sort({name:1}) |
SELECT * FROM users WHERE name LIKE "%Joe%" | db.users.find({age:{$gt:33}}) |
SELECT * FROM users WHERE name LIKE "Joe%" | db.users.find({age:{$ne:33}}) |
SELECT * FROM users WHERE age>33 AND age<=40 | db.users.find({name:/Joe/}) |
SELECT * FROM users ORDER BY name DESC | db.users.find({name:/^Joe/}) |
SELECT * FROM users WHERE a=1 and b='q' | db.users.find({'age':{$gt:33,$lte:40}}) |
SELECT * FROM users LIMIT 10 SKIP 20 | db.users.find().sort({name:-1}) |
SELECT * FROM users WHERE a=1 or b=2 | db.users.find({a:1,b:'q'}) |
SELECT * FROM users LIMIT 1 | db.users.find().limit(10).skip(20) |
SELECT order_id FROM orders o, order_line_items li WHERE li.order_id=o.order_id AND li.sku=12345 | db.users.find( { $or : [ { a : 1 } , { b : 2 } ] } ) |
SELECT customer.name FROM customers,orders WHERE orders.id="q179" AND orders.custid=customer.id | db.users.findOne() |
db.orders.find({"items.sku":12345},{_id:1}) | |
SELECT DISTINCT last_name FROM users | var o = db.orders.findOne({_id:"q179"}); |
SELECT COUNT(*y) | var name = db.customers.findOne({_id:o.custid}) |
FROM users | |
SELECT COUNT(*y) | db.users.distinct('last_name') |
FROM users where AGE > 30 | db.users.count() |
SELECT COUNT(AGE) from users | db.users.find({age: {'$gt': 30}}).count() |
db.users.find({age: {'$exists': true}}).count() | |
CREATE INDEX myindexname ON users(name) | |
CREATE INDEX myindexname ON users(name,ts DESC) | db.users.ensureIndex({name:1}) |
db.users.ensureIndex({name:1,ts:-1}) | |
EXPLAIN SELECT * FROM users WHERE z=3 | |
db.users.find({z:3}).explain() | |
UPDATE users SET a=1 WHERE b='q' | |
UPDATE users SET a=a+2 WHERE b='q' | db.users.update({b:'q'}, {$set:{a:1}}, false, true) |
db.users.update({b:'q'}, {$inc:{a:2}}, false, true) | |
DELETE FROM users WHERE z="abc" | db.users.remove({z:'abc'}); |
Open Source & much more
Looking for Open Source Help??? Here is Blog for it's A-to-Z. Attempt is to crawl along all the codes & concepts
Sunday, May 13, 2012
SQL to Mongo Mapping Chart
Profiling PHP Applications on Apache Using Xdebug and Xdebugtoolkit
Your app is slow?You can take a
real deep look into your application using the profiling options of Xdebug.
How To:
We will be using RHEL /
CentOS as operating system for this tutorial. For more information about installing Xdebug, get it here.
1. Assuming that you have PEAR/PECL installed, get Xdebug by,
# pecl install xdebug
The command above will install the xdebug.so module to your php modules directory which is usually located at /usr/lib64/php/modules (part of distribution) or /usr/local/lib/php/modules (user installed).
2. Activate the xdebug module by adding the following entry to php.ini.
zend_extension = /path/to/xdebug.so or zend_extension = xdebug.so
Note: xdebug is a zend extension, DO NOT use "extension=xdebug.so". This will fail.
You can place the entry above to php.ini by doing any of the following:
# vi /etc/php.ini, copy and paste into a line within the config, then save (ESC + colon + wq)
Or, if your php configuration was installed using dependency structure (/etc/php.d), you can simply do the following,
# cd /etc/php.d
# vi xdebug.ini, copy and paste into a line within the config, then save (ESC + colon + wq)
To configure, you can use the sample below, and paste it after the "zend_extension" module entry.
Xdebug Automatic Mode:
xdebug.profiler_enable = on
xdebug.profiler_output_dir = /tmp
xdebug.profiler_output_name => cachegrind.out.%t-%R
Xdebug Trigger Mode:
xdebug.profiler_enable = off
xdebug.profiler_enable_trigger = on
xdebug.profiler_output_dir = /tmp
xdebug.profiler_output_name => cachegrind.out.%t-%R
3. Restart apache for changes to take effect.
# /etc/init.d/httpd restart
1. Assuming that you have PEAR/PECL installed, get Xdebug by,
# pecl install xdebug
The command above will install the xdebug.so module to your php modules directory which is usually located at /usr/lib64/php/modules (part of distribution) or /usr/local/lib/php/modules (user installed).
2. Activate the xdebug module by adding the following entry to php.ini.
zend_extension = /path/to/xdebug.so or zend_extension = xdebug.so
Note: xdebug is a zend extension, DO NOT use "extension=xdebug.so". This will fail.
You can place the entry above to php.ini by doing any of the following:
# vi /etc/php.ini, copy and paste into a line within the config, then save (ESC + colon + wq)
Or, if your php configuration was installed using dependency structure (/etc/php.d), you can simply do the following,
# cd /etc/php.d
# vi xdebug.ini, copy and paste into a line within the config, then save (ESC + colon + wq)
To configure, you can use the sample below, and paste it after the "zend_extension" module entry.
Xdebug Automatic Mode:
xdebug.profiler_enable = on
xdebug.profiler_output_dir = /tmp
xdebug.profiler_output_name => cachegrind.out.%t-%R
Xdebug Trigger Mode:
xdebug.profiler_enable = off
xdebug.profiler_enable_trigger = on
xdebug.profiler_output_dir = /tmp
xdebug.profiler_output_name => cachegrind.out.%t-%R
3. Restart apache for changes to take effect.
# /etc/init.d/httpd restart
- Install
Xdebugtoolkit
1. Assuming that you have subversion installed, get xdebugtoolkit
# svn co http://xdebugtoolkit.googlecode.com/svn/tags/0.1.4/xdebugtoolkit/ xdebugtoolkit
2. Make sure that you have installed all dependencies. For more information, go to xdebugtoolkit.
# yum install python
# yum install pygtk2
# yum install graphviz , this will install "dot" on /usr/bin/dot
# svn co http://xdebugtoolkit.googlecode.com/svn/tags/0.1.4/xdebugtoolkit/ xdebugtoolkit
2. Make sure that you have installed all dependencies. For more information, go to xdebugtoolkit.
# yum install python
# yum install pygtk2
# yum install graphviz , this will install "dot" on /usr/bin/dot
- Generate
Cachegrind or Application Profile Data
For Xdebug Automatic
Mode, just visit the URLs that you want profiled. In our case, we used QAs
regression test to fully profile the application.
For Xdebug Trigger Mode, just append XDEBUG_PROFILE=1 after each URL.
e.g http://yourdomain.com/?XDEBUG_PROFILE=1
For Xdebug Trigger Mode, just append XDEBUG_PROFILE=1 after each URL.
e.g http://yourdomain.com/?XDEBUG_PROFILE=1
- Generate
Graphs
·
# cd /tmp
·
#
/path/to/xdebugtoolkit/cg2dot.py yourcachegrindfile | /path/to/dot -T png -o
/path/to/file.png
Subscribe to:
Posts (Atom)