We are Web Technology Experts Team who provide you Important information on Web Development, Interview Questions and Answers, live project problem and their solution and online free tutorials.
Tuesday 22 October 2019
Monday 21 October 2019
Symfony2 Interview Questions and Answers for Beginners
Question: What is Symfony?
Symfony is a PHP web application framework for MVC applications.
Question: Is Symfony Open Source?
Yes, It is Open Source.
Question: What is current Stable version of Symfony?
Version: 5.0.4, Dated: 31 Jan 2020
Question: What is offical website of Symfony?
symfony.com
Question: What is minimum PHP Version requirement for Symfony?
PHP 7.2.5
Question: What are benefits of Symfony?
- Fast development
- MVC Pattern
- Unlimited flexibility
- Expandable
- Stable and sustainable
- Ease of use.
Question: How to concatenate strings in twig?
{{ 'http://' ~ app.request.host }}
Question: How to get current route in Symfony 2?
$request = $this->container->get('request'); $currentRouteName = $request->get('_route');
Question: How to render a DateTime object in a Twig template?
{{ game.gameDate|date('Y-m-d') }}
Question: How to var_dump variables in twig templates?
{{ dump(user) }}
Question: How to get the request parameters in symfony2?
$name=$request->query->get('name');
Question: How to get list of all installed packages in composer?
composer global show
Best Related Posts are Following:
- Laravel Interview Questions and Answers.
- YII interview questions and answers for fresher.
- Python Interview Questions and Answers for Freshers.
- OOP Interview Questions and Answers.
- jQuery Mobile interview questions and answers.
- AngularJS Interview Questions and Answers for Experienced.
- Apache Interview Questions and Answers.
- Magento interview questions and answers for experienced.
- Android Interview Questions and Answers for fresher and Experienced.
- Ajax Interview Questions and Answer for 1 Year Experienced.
- Javascript Interview Questions and Answers for Experienced.
- Paypal Integration Interview Questions and Answers.
- Android Interview Questions and Answers for Freshers.
- Ajax Interview questions and answers for experienced.
- Bootstrap Interview Questions and Answers for Experienced.
Sunday 13 October 2019
How to create http server in NodeJS?
Question: How to create a New server in nodejs?
var http = require("http"); http.createServer(function(request, response) { response.writeHead(200, {'Content-Type': 'text/html'}); response.write(""); response.write(""); response.write(" Hello World Page "); response.write(""); response.write(""); response.write("Hello World!"); response.write(""); response.write(""); response.end(); }).listen(8081);
Question: How to Execute above response in browser?
http://127.0.0.1:8081/
You should be already installed WampServer/Xampp Server.
Question: How to install httpdispatcher?
npm install httpdispatcher
Question: Give an example of http GET Request?
dispatcher.onGet("/contactus", function(req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); res.end(' Contact US Page
'); });
Question: Give an example of http POST Request?
dispatcher.onPOST("/contactus", function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end(' Received POST Data
'); });
Question: Give an full example of httpdispatcher which have multiple pages?
var dispatcher = require('httpdispatcher'); function handleRequest(request, response) { try { //log the request on console console.log(request.url); //Disptach dispatcher.dispatch(request, response); } catch (err) { console.log(err); } } dispatcher.setStatic('resources'); //A sample GET request dispatcher.onGet("/contactus", function(req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); res.end(' Contact US Page
'); }); dispatcher.onGet("/aboutus", function(req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); res.end('About US Page
'); }); var http = require('http'); var server = http.createServer(handleRequest); //Lets start our server server.listen(8081, function() { //Callback triggered when server is successfully listening. Hurray! console.log("Server listening on: http://localhost:%s", 8081); });
Best Related Posts are Following:
Saturday 12 October 2019
How to install and Connect to MySQL in NodeJS?
Hope you have already installed nodeJS, If not Please install first.
https://nodejs.org/en/download/
Question: How to install new package in nodejs?
npm install packagename
Question: How to install MySQL?
npm install mysql
Question: How to update MySQL?
npm update mysql
Question: How to include MySQL?
var mysql = require("mysql");
Question: How to connect to MySQL in nodeJS?
var mysql = require("mysql"); var con = mysql.createConnection({ host: "localhost", user: "root", password: "", database: "mydb" }); con.connect(function(err) { if (err) { console.log('Error connecting to database'); return; } console.log('Connection established Successfully'); });
Question: How to connect to MySQL in single string in nodeJS?
var mysql = require("mysql"); var con = mysql.createConnection('mysql://arun:arun@localhost/database'); con.connect(function(err) { if (err) { console.log('Error connecting to database'); return; } console.log('Connection established Successfully'); });
Question: How to get records from MySQL database in node.js?
var mysql = require("mysql"); var con = mysql.createConnection({ host: "localhost", user: "root", password: "", database: "enterprisedev2" }); con.query('SELECT * FROM admin_members where id<=10 ', function(err, rows) { for (var i = 0; i < rows.length; i++) { console.log(rows[i]); } });
Question: How to insert record in database?
var mysql = require("mysql"); var con = mysql.createConnection('mysql://arun:arun@localhost/mydb'); var post = { 'userID': "1", 'userName': 'username', 'device': 'web', 'stream_time': "0", 'user_display_name': "arun kumar gupta", 'user_photo': "hello" }; con.query('INSERT INTO messages set ?', post, function(err, result) { if (err) { console.log(err.message); } else { console.log('record added in db'); } });
Question: How to print the query while inserting record?
var mysql = require("mysql"); var con = mysql.createConnection('mysql://arun:arun@localhost/mydb'); var post = { 'userID': "1", 'userName': 'username', 'device': 'web', 'stream_time': "0", 'user_display_name': "arun kumar gupta", 'user_photo': "hello" }; var mysqlProfiler = con.query('INSERT INTO messages set ?', post, function(err, result) {}); console.log(mysqlProfiler.sql);
Question: Given another way to insert data in MySQL Database?
var mysql = require("mysql"); var con = mysql.createConnection('mysql://arun:arun@localhost/enterprisedev2'); /* data insert in db */ var postData = { userID: "1", userName: "arunkg", userRole: "1", text: 'kkkkkkkkkkkkkkkk', status: "1", vid: '21' }; var mysqlProfiler = con.query('INSERT INTO `messages` (`userID`, `userName`, `userRole`,`text`,`status`,`vid`) VALUES (' + [postData.userID, mysql.escape(postData.userName), postData.userRole, mysql.escape(postData.text), postData.status, postData.vid] + ')', function(err, result) { if (err) { //console.log(err.message); } else { console.log('record added in db'); } });
Thursday 10 October 2019
How to speed up your application with MongoDb?
1) Make Sure you application have Sufficient RAM
If your application don't have enough RAM, then please increase it.
2) Analyze Your Queries
Analyse the queries with explain like below:
db.user.find('{"likes": {$gt:10}"likes"}').explain("executionStats");You can check the problem with the queries and fix the issue.
Also please fetch only those records which are using. Don't fetch un-necessary field and records from database.
3) Limit the Records
If you are using 10 records but getting 100 records. Means you are getting 99 record extra that is wrong. So please limit the record with limit command.
db.user.find('{"likes": {$gt:10}"likes"}').limit(10);
4) Add Appropriate Indexes
You can use the index wherever are required (most used in search query). You can add indexes on Single/Multiple field. In this way you can speed the application by speedup the queries.
db.user.createIndex({ country: 1 });
5) Sorting
Un-necessary sorting can also have problem, So sort the records wherever required. Avoid un-necessary sorting. Example of Sorting (-1 no sorting, 1 ascending , 0 descending )
Sort by Country and then City.
db.user.find().sort({ country: 1, city: 1 });
Sort by Country only (Even we have added city in our indexes).
db.user.find().sort({ country: 1, city: -1 });
Sort by city only (Even we have added country in our indexes).
db.user.find().sort({ country: -1, city: 1 });
6) Check Your MongoDB Log
As we know, logging the queries take some time to logged. It make take about 100Mili seconds for each log query.
So, You should log the queries carefully because un-necessary loging data may slow the system.
db.setLogLevel(0);0 is the MongoDB's default log verbosity level, to include Informational messages.
1 to 5 increases the verbosity level to include Debug messages.
7) Understand the Query Profiling
You can get Profiling Level (current).
db.getProfilingLevel()
You can set Profiling Level.
db.setProfilingLevel(1)
Following the 3 Profiling Level.
- -1 for inherit the profiling from parent.
- 0 for no profiling.
- 1 for slow operations.
- 2 for all operations.
8) Multiple Database Connection
If you are running heavy site and few queries are taking taking more time due to which queries are completing in asynchronous.
Means query start time are q1, q2, q3 but completing time are q2,q1,q3.
To fix this problem.
For this, you can create multiple Database connection and handle like below:
- One to handle the majority of fast queries.
- One to handle slower document inserts and updates.
- One to handle complex report generation.
9) Set Maximum Execution time
MongoDB commands run as long as they need. A slowly-executing query can hold up others, and your web application may time out.
You can set the max execution time like below:
db.user.find('{"likes": {$gt:10}"likes"}').maxTimeMS(100);
10) Rebuild Your Indexes
You need re-index, if your collection fall in following:
- Collection size has increased significantly.
- Indexes are consuming a disproportionate amount of disk space.
Best Related Posts are Following:
- MongoDB indexing and Embed document.
- MongoDB Questions and Answers for beginners.
- MongoDB Interview Question And Answers for 1 Year Experience.
- What is sharding in MongoDB?.
- What is difference between Mongoexport and Mongodump.
- MongoDB export and Import databases with Example.
- MongoDB Cursor with Examples.
- MongoDB update and delete records with examples.
- Mongodb index commands with examples.
- Angularjs listing example with JSON.
Saturday 5 October 2019
FuelPHP Interview Questions and Answers for Beginners
Question: What is FuelPHP?
FuelPHP is PHP Framework written in PHP, based on the HMVC pattern.
Question: Is FuelPHP Open Source?
Yes, It is Open Source.
Question: What is minimum PHP Version required for FulePHP?
PHP 5.4+
Question: Is FulePHP support Multilingual?
Yes, It support Multilingual.
Question: What is offical website of FulePHP?
fuelphp.com
Question: What are Key Features of FuelPHP?
- URL routing system
- RESTful implementation
- HMVC implementation
- Form Data validation
- ORM (Object Relational Mapper)
- Vulnerability protections like XSS, CSRF, SQL Protection and encode output.
- Caching System
Question: What is full form of HMVC?
Hierarchical-Model-View-Controller
Question: What is HMVC?
HMVC is an evolution of the MVC pattern.
Question: What are benefits of HMVC?
- Modularization
- Organization
- Reusability
- Extendibility
Question: How to get Query in FulePHP?
$userQueryToExecute = Model_Article::query() ->select('users') ->where('blocked', '=', 1); echo $userQueryToExecute->get_query();
Question: How to check that Redis server is running?
try { $redis = \Redis::instance(); } catch(\RedisException $e) { //here error will come }
Question: How to use join with condition?
$queryObj = \Services\Model_Org::query() ->related('org') ->related('profile_image')->related( array( 'comments' => array( 'where' => array( array('visible' , '=' , '0') ) ) )) ->where('rating','!=', 'null') ->order_by('rating','desc') ->get();
Best Related Posts are Following:
- Laravel Interview Questions and Answers.
- YII interview questions and answers for fresher.
- Python Interview Questions and Answers for Freshers.
- OOP Interview Questions and Answers.
- jQuery Mobile interview questions and answers.
- AngularJS Interview Questions and Answers for Experienced.
- Codeigniter Interview Questions for Experienced.
- SMTP interview questions and answers.
- Apache Interview Questions and Answers.
- Magento interview questions and answers for experienced.
- Frontend Interview Questions and Answers for experienced.
- Android Interview Questions and Answers for fresher and Experienced.
- Htaccess interview Questions and Answers for fresher and experienced.
- Javascript Interview Questions and Answers for Experienced.
- Paypal Integration Interview Questions and Answers.
- Android Interview Questions and Answers for Freshers.
- HTML5 interview Questions and Answers for Fresher and Experienced.
- SAML Interview Questions and Answers.
- Backbone Js interview questions and answers.
- Bootstrap Interview Questions and Answers for Experienced.
- HTML interview questions and Answers.
- SEO Interview Questions and Answers.
- Wordpress Interview Questions and Answers.
- Difference Between Hadoop and Big-Data.
- Memcached interview questions and answers.
- UNIX Commands Interview Questions and Answer
Thursday 3 October 2019
What is Super Key, Candidate keys and Alternate Key?
Super Key
A Super key is any combination of fields within a table that uniquely identifies each record within that table.
Example:
managers (table)
ManagerID (unique) Name Title DepartmentID
ManagerID+Name=Super Key
ManagerID+Title=Super Key
Candidate keys
Candidate keys are those keys which is candidate for primary key of a table. Candidate keys are such keys which full fill all the requirements of primary key which is not null and have unique records.
Example:
Suppose we have a table named Employee which has two columns EmpID and EmpMail, both are not null and have unique value. Both Field are Candidate keys.
Alternate Key
If any table have more than one candidate key, then after choosing primary key from those candidate key, rest of candidate keys are known as an alternate key of that table.
Example:
Suppose we have a table named Employee which has two columns EmpID and EmpMail, both are not null and have unique value. So both columns are treated as candidate key. IF we make EmpID as a primary key, then EmpMail is known as alternate key.
Referential integrity
Referential integrity is a database concept that ensures that relationships between two table remain consistent.
Suppose one table has a foreign key to another table. Referential integrity makes ensure the both have valid record.
Example:
products (table) id (primary key) name price sale_price size
reviews (another table) id (primary key), product_id (foreign key) review by title start_rating
One Product can have one Or multiple reviews.
Referential integrity make sure following:
- You can't delete record from product table, till review exist in reviews table for same product Id.
- You can't add record in reviews table, till you have not added record in product table for same product Id.
- If you delete the record from product table, reviews will be deleted automatically using cascade for the same product Id.
Best Related Posts are Following:
- MySQL Query Optimization Tips and Techniques.
- How can I make SQL Query case sensitive string comparison on MySQL?.
- DBMS Interview Questions and Answers for Freshers.
- MySQL Interview Questions and Answers for Experienced.
- Difference between inner join and outer join in MySQL.
- How to get a list of MySQL user accounts?.
- How to delete MySQL Binary logs Files in Wamp Server?.
- SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 2269548 for key PRIMARY.
- Multiple column ordering in Zend Framework.
- Mysql Privileges - Types of privileages in MySql - How do I grant privileges in MySQL.
- Difference Between Primary Key And Unique Key And Foreign Key And Composite Key.
- Difference Between MyISAM and innoDB - MySQL.
- MySQL Functions - MySQL tutorial for beginners.
- mysqlsubqueries examples Scalar Subqueries Row Subqueries Column Subqueries Table Subqueries.
- Mysql FullText Search Examples.
- MySQL Constraint Example.
- MySQL Cascade Example.
- Mysql-Group-Concat.
- MySQL Expressions.
- MySQL Delete Table Example.
- Replace Table - Update Field, Move Records to another table MySQL.
- mysql insert syntax - Add records from another table - Copy Table from one table to another.
- Mysql Update Syntax - Update Multiple Records.
- What is Mysql.
- Mysql Console Commands - Export and Import database from command line.
- MySQL interview Questions and Answers For Experienced.
Friday 27 September 2019
MongoDB Questions and Answers for beginners
Question: What kind of NoSQL database used in MongoDB?
MongoDB is a document oriented database. It store data in form of BSON structure.
Question: What is a Namespace in MongoDB?
Namespace is concatenation of the database name and collection name.
Question: Does MongoDB support foreign key constraints?
No.
Question: Does MongoDB support ACID transaction?
No.
Question: Does MongoDB support Indexes?
Yes.
Question: Does MongoDB support primary key & foreign key relationships in MongoDB?
No, By Default it does not support. But we can achieve this by using embedding one document inside another.
Question: How is MongoDB better than other SQL databases?
Namespace is concatenation of the database name and collection name.
- Highly flexible
- Scalable Document
- Fast
- Replication
Question: When we removed an document. Does it removed permanently?.
Yes, When we rmoved and document it delete from disk.
Question: When we removed an document. Does it removed permanently?.
Yes, When we rmoved and document it delete from disk.
Question: What happens if an index does not fit into RAM?.
In that case MongoDB reads data from disk which is relatively very much slower.
Question: What is a covered query in MongoDB?.
Covered query is the one in which, A) fields used in the query are part of an index
AND
B) the fields returned in the results are in the same index.
Question: What is Aggregation in MongoDB??.
Aggregation is process of data-records and return computed results.
Question: What is Sharding in MongoDB??.
Sharding is a method for storing data across multiple machines (2 OR more machines).
Question: What is Replication in MongoDB?.
Replication is a process of synchronizing data across multiple servers.
Question: What are Primary and Secondary Replica sets?
Primary and master nodes are the nodes that can accept writes.
Secondary and slave nodes are read-only nodes that replicate from the primary.
Question: Why are MongoDB data files large in size?
MongoDB preallocates data files to reserve space and avoid file system fragmentation when you setup the server.
Question: What is a Storage Engine in MongoDB?
A storage engine is responsible for managing data like how data is stored on disk.
Question: What are two storage engines used by MongoDB?
1) MMAPv1
2) WiredTiger
Question: Why MongoDB is not preferred over a 32-bit system??
In 32-bit build system the total storage size for the server including data and indexes is 2GB.
Question: What is the role of a profiler in MongoDB??
The Profiler collects fine grained data about MongoDB write operations, cursors, database commands.
Question: How does MongoDB provide concurrency?
MongoDB uses reader-writer locks for the concurrency.
Question: What is hotfix for windows?
A hotfix is single/cumulative package to fix an issue.
Question: How to changes in storage path of MongoDB?
mongod --dbpath "d:\mongodb\data"
Question: How to get mongoDB Version ?
mongod --version
Best Related Posts are Following:
- MongoDB Interview Question And Answers for 1 Year Experience.
- What is sharding in MongoDB?.
- What is difference between Mongoexport and Mongodump.
- MongoDB export and Import databases with Example.
- MongoDB Cursor with Examples.
- MongoDB update and delete records with examples.
- Mongodb index commands with examples.
- Angularjs listing example with JSON.
- MongoDB Interview Questions and Answer for 1 Year Experienced.
- MongoDB operators with examples.
- MongoDb PHP functions Questions and Answers.
- How to Configure MongoDB with PHP for WampServer on Windows.
- MongoDb Technical Interview Questions and Answers.
- MongoDB Interview Questions and Answers.
- How to install MongoDB install on window 7.
- MongoDB - Where and Why should we use MongoDb?.
- Advance MongoDB Interview Questions and Answer.
- MongoDB Interview Questions and Answer on Database.
- MongoDB Database Commands with Examples.
- Comparison between MySQL and MongoDB.
Wednesday 25 September 2019
MongoDB indexing and Embed document
Question: How to create indexing on single column?
db.users.ensureIndex({"title":1})1- Indexing in Ascending Order.
Question: How to create indexing on multiple column?
db.users.ensureIndex({"title":1,"description":-1})1- Indexing in Ascending Order.
-1- Indexing in Descendig Order.
Question: How to make unique key in MongoDB?
db.users.ensureIndex({"username":1},{unique:true,sparse:true})Now you can't add duplicate username in users collection.
Question: What is sparse in MongoDB indexing?
Sparse indexes only contain entries for documents that have the indexed field. The index skips over any document that is missing the indexed field. The index is sparse because it does not include all documents of a collection. .
Question: How to create indexing in background process?
db.users.ensureIndex({"title":1},{background:true})
Question: How to create indexing on column which can have duplicate values?
db.users.ensureIndex({"title":1},{dropDups:true})
Question: How can we set index name while creating indexing?
db.users.ensureIndex({"title":1},{name:'bankdb_users_index'})
Question: How to drop an index on single column?
db.users.dropIndex({"title":1})
Question: How to drop all indexes on document?
db.users.dropIndexex()
Question: How to update all index in collection?
db.collection.reIndex()
Question: How to create indexing in Embed document?
db.users.ensureIndex({"profile.city":1})
Search Document From Embed document
db.users.find( { "profile.city" : "newYork" } )
Question: Compare "Multiple collections" vs "Embedded documents"?
- No much differences for insertion and updates document.
- Separate collections are better when you need to select individual documents and gives more control over querying.
- Embedded documents are better when embed document is less OR No More.
- Getting record from embedded documents is easy as compare Multiple collections.
- Embed document limit is 16MB
Relationships denotes how various documents are logically related to each other.
Question: What are different ways to achieve the relationships in MongoDB?
Following are various two Approaches
1) Embedded Approaches 2) Referenced Approaches
Question: Given an example of Embedded?
[ { "_id": ObjectId("52ffc33cd85242f436099901"), "contact": "987654321", "dob": "01-01-1991", "name": "Tom Benzamin", "address": [ { "pincode": 123456, "city": "Los Angeles", "state": "California" }, { "pincode": 456789, "city": "Chicago", "state": "Illinois" } ] } ]
Question: Given an example of Referenced?
[ { "_id": ObjectId("52ffc33cd85242f436099901"), "contact": "987654321", "dob": "01-01-1991", "name": "Tom Benzamin", "address": [ ObjectId("63ffc4a5d85242602e000000"), ObjectId("63ffc4a5d85242602e000001") ] } ]
Best Related Posts are Following:
- MongoDB Interview Question And Answers for 1 Year Experience.
- What is sharding in MongoDB?.
- What is difference between Mongoexport and Mongodump.
- MongoDB export and Import databases with Example.
- MongoDB Cursor with Examples.
- MongoDB update and delete records with examples.
- Mongodb index commands with examples.
- Angularjs listing example with JSON.
- MongoDB Interview Questions and Answer for 1 Year Experienced.
- MongoDB operators with examples.
- MongoDb PHP functions Questions and Answers.
- How to Configure MongoDB with PHP for WampServer on Windows.
- MongoDb Technical Interview Questions and Answers.
- MongoDB Interview Questions and Answers.
- How to install MongoDB install on window 7.
- MongoDB - Where and Why should we use MongoDb?.
- Advance MongoDB Interview Questions and Answer.
- MongoDB Interview Questions and Answer on Database.
- MongoDB Database Commands with Examples.
- Comparison between MySQL and MongoDB.
Sunday 22 September 2019
MongoDB Interview Question And Answers for 1 Year Experience
Question: How do I query mongodb with like ?
Following are few example of like as compare to SQL Query
/*select * from users where name like "%B%";*/ db.users.find({name: /B/});
/*select * from users where name like "B%"; */ db.users.find({name: /^B/});
/*select * from users where name like "%B"; */ db.users.find({name: /B$/});
Question: How to execute case in sensitive query?
/*select * from users where name like "%B%" OR like "%b%"; */ db.users.find({name: /b/i});
Question: How to list all collections in the mongoDB?
Following are three different methods.
db.getCollectionNames()
show collections
show tables
Question: Pretty print in MongoDB shell?
Normally we use query as below:
db.users.find()
For Pretty display, use like below:
db.users.find().pretty()
Question: How to get the last N records?
db.users.find().sort({_id:-1}).limit(20); /* -1 means descending order */
Question: How to export collection into CSV?
mongoexport --host localhost --db bank --collection users --csv --out e:/dump/mycsv.csv --fields name,age,gender
Question: How to import into collection from CSV?
mongoimport -d bank -c users --type csv --file e:/dump/mycsv.csv --headerline
Question: How can I rename a field for all documents in MongoDB?
db.students.updateMany( {}, { $rename: { "name": "full_name" } } )
Question: How to store date/time in mongodb
db.users.insert({date: ISODate("2014-02-10T10:50:42.389Z")})
Best Related Posts are Following:
- What is sharding in MongoDB?.
- What is difference between Mongoexport and Mongodump.
- MongoDB export and Import databases with Example.
- MongoDB Cursor with Examples.
- MongoDB update and delete records with examples.
- Mongodb index commands with examples.
- Angularjs listing example with JSON.
- MongoDB Interview Questions and Answer for 1 Year Experienced.
- MongoDB operators with examples.
- MongoDb PHP functions Questions and Answers.
Thursday 19 September 2019
MongoDB Cursor with Examples
Question: What is cursor in MongoDB?
Cursor is a pointer to the result set of a query.
When you run a query for documents we retrieve a pointer (cursor) to the results instead of all result return.
Question: Give example of Cursor?
var myCursor=db.users.find({"age":30}); while (myCursor.hasNext()) { print(tojson(myCursor.next())); }
Question: How to get the data type of variable?
var data=10; typeof data; var data='10'; typeof data;Output
number string
Question: What is use of forEach with Cursor?
Iterates the cursor to each document.
Example 1
db.users.find({"age":30}).forEach(printjson);
Example 2
db.users.find({"age":30}).forEach(function(data){ print(data.name); });Output
name1 name2 name3
Question: How to use limit with Query?
db.users.find({"age":30}).limit(5).pretty();Now, cursor will return maximum 5 records.
Question: How to get results in Array instead of JSON?
db.users.find({"age":30}).toArray()
Question: How to get number of results from Query?
db.users.find({"age":30}).size(); //2
Question: How to sort records by name in Ascending order?
db.users.find({"age":30}).sort({"name":1}).forEach(function(data){print(data.name);});
Question: How to sort records by name in Descending order?
db.users.find({"age":30}).sort({"name":-1}).forEach(function(data){print(data.name);});
Question: How to skip 4th record from query?
db.users.find({"age":30}).skip(4).forEach(function(data){print(data.name);});
Question: How to search records with indexing?
db.users.find({"age":30}).hint({"age":1}).pretty();
Best Related Posts are Following:
- MongoDB update and delete records with examples.
- Mongodb index commands with examples.
- Angularjs listing example with JSON.
- MongoDB Interview Questions and Answer for 1 Year Experienced.
- MongoDB operators with examples.
- MongoDb PHP functions Questions and Answers.
- How to Configure MongoDB with PHP for WampServer on Windows.
- MongoDb Technical Interview Questions and Answers.
- MongoDB Interview Questions and Answers.
- How to install MongoDB install on window 7.
- MongoDB - Where and Why should we use MongoDb?.
- Advance MongoDB Interview Questions and Answer.
- MongoDB Interview Questions and Answer on Database.
- MongoDB Database Commands with Examples.
- Comparison between MySQL and MongoDB.
Wednesday 18 September 2019
What is sharding in MongoDB?
Question: What is sharding in MongoDB?
Sharding is a method for distributing data across multiple machines and its MongoDB's approach to meeting the demands of data growth. With increase of the size of the data, a single machine may not be sufficient to store the data OR read and write data. to fix this problem there are two different methods.
Vertical Scaling: Increase the capacity of single server and increase the power.
- Powerful CPU
- Increase RAM
- Increase storage
Horizontal Scaling: dividing the system dataset and load over multiple servers.
We can use multiple server for storing and read/data data.
Using multiple server is lower cost than single machine with high-end hardware but increase the complexity in infrastructure and maintenance for the deployment.
Question: What are MongoDB Query Capabilities?
- Sorting on one/multiple fields with ascending/descending order.
- Projection (Retrieving only specified fields from each document in the cursor, not the entire document).
- Cursor skip() and limit() to easily implement pagination.
- explain() will return the detail on query will help to optimize the query.
- aggregate() function used for grouping the records. db.users.aggregate([{$match:{gender:"male"}}, { $group: { _id: null, count: { $sum: 1 } } }]);
- $match and $unbind function.
Question: How to database details?
db.stats();
Output
{ "db": "bank", "collections": 4, "objects": 12, "avgObjSize": 245.33333333333334, "dataSize": 2944, "storageSize": 28672, "numExtents": 4, "indexes": 2, "indexSize": 16352, "fileSize": 67108864, "nsSizeMB": 16, "extentFreeList": { "num": 0, "totalSize": 0 }, "dataFileVersion": { "major": 4, "minor": 22 }, "ok": 1 }
Question: How to collection details?
db.users.stats();Output
{ "ns": "bank.users", "count": 5, "size": 2480, "avgObjSize": 496, "numExtents": 1, "storageSize": 8192, "lastExtentSize": 8192, "paddingFactor": 1, "paddingFactorNote": "paddingFactor is unused and unmaintained in 3.0. It remains hard coded to 1.0 for compatibility only.", "userFlags": 1, "capped": false, "nindexes": 1, "totalIndexSize": 8176, "indexSizes": { "_id_": 8176 }, "ok": 1 }
Best Related Posts are Following:
- What is difference between Mongoexport and Mongodump.
- MongoDB export and Import databases with Example.
- MongoDB Cursor with Examples.
- MongoDB update and delete records with examples.
- Mongodb index commands with examples.
- Angularjs listing example with JSON.
- MongoDB Interview Questions and Answer for 1 Year Experienced.
- MongoDB operators with examples.
- MongoDb PHP functions Questions and Answers.
- How to Configure MongoDB with PHP for WampServer on Windows.
- MongoDb Technical Interview Questions and Answers.
- MongoDB Interview Questions and Answers.
- How to install MongoDB install on window 7.
Monday 16 September 2019
Angularjs listing example with JSON
JSON Data load_data.php[script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"][/script] [script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.js"][/script] [style] .secdsubmenu{position:absolute; right:22px; top:2px; border:1px solid #eee; background:#fff; z-index:99} .secdsubmenu ul {padding:10px; margin:0} .secdsubmenu ul li{list-style:none; font-size:13px; color:#333; padding:0; margin:0; white-space:nowrap; border-bottom:1px solid #eee; height:30px; line-height:30px; } .secdsubmenu ul li a{color:#333; text-decoration:none} [/style] [script] var myApp = angular.module('myAppName', ['ngAnimate']); myApp.controller('myCtrl', function($scope, $http) { $http.get("load_data.php") .then(function(response) { $scope.names = response.data.records; }); $scope.mySubmenu = false; $scope.Title = 'title'; $scope.reverse = true; $scope.sortBy = function(title) { $scope.reverse = ($scope.title === title) ? !$scope.reverse : false; $scope.title = title; }; }); [/script]
Title Date & Time Status Action {{x.Title}} {{x.DateTime}} {{x.Status}} ...
{ "records":[ {"Title":"Title 1","DateTime":"Jul 29 2016, 01:00 AM","Status":"Completed"}, {"Title":"Title 2","DateTime":"Jul 28 2016, 02:00 PM","Status":"Completed"}, {"Title":"Title 3","DateTime":"Jul 27 2016, 03:00 AM","Status":"Completed"}, {"Title":"Title 4","DateTime":"Jul 26 2016, 04:00 AM","Status":"Completed"}, {"Title":"Title 5","DateTime":"Jul 25 2016, 05:00 AM","Status":"Completed"}, {"Title":"Title 6","DateTime":"Jul 24 2016, 06:00 AM","Status":"Completed"}, {"Title":"Title 7","DateTime":"Jul 23 2016, 09:00 AM","Status":"Completed"}, ]}
Best Related Posts are Following:
- MongoDb PHP functions Questions and Answers.
- How to Configure MongoDB with PHP for WampServer on Windows.
- MongoDb Technical Interview Questions and Answers.
- MongoDB Interview Questions and Answers.
- How to install MongoDB install on window 7.
- MongoDB - Where and Why should we use MongoDb?.
- Advance MongoDB Interview Questions and Answer.
- MongoDB Interview Questions and Answer on Database.
- MongoDB Database Commands with Examples.
- Comparison between MySQL and MongoDB.
Thursday 12 September 2019
New PHP 7 Feature List
Question: Why we should use PHP 7 as compare to PHP5?
- Improved performance. Its twice as fast as compare to PHP 5.
- Lower Memory Consumption.
- Scalar type declarations.
- Return and Scalar Type Declarations.
- Consistent 64-bit support
- Many fatal errors converted to Exceptions
- Secure random number generator.
- Various old and unsupported SAPIs and extensions are removed from the latest version
- NULL coalescing operator removed
- Anonymous Classes Added.
- Zero cost asserts
- Use of new Zend Engine 3.0
Question: What is PHPNG?
PHPNG branch has been merged into master and has been used as the base for PHP 7.0.
PHPNG target is improve the performance and memory usage efficiency of PHP.
Question: What is a PHP parser?
PHP parser is a software which understand your coding and convert to computer language So that it can be executed & gives a output in HTML.
Question: What is a Scalar type declarations?
Allowing/prohibited datatype declaration in functions know for Scalar type declarations.
There are two options in Scalar type declarations
1) Coercive Mode (default)
2) Strict Mode
function sum(int ...$ints) { return array_sum($ints); } print(sum(2, '20', 4.2)); //26.2
Question: How to use return type declarations?
function returnIntValue(int $value): int { return $value; } print(returnIntValue(5));
Question: What is spaceship operator?
It is Operator which is used to compare two expressions.
It return -1, 0 or 1.
print( 1 <=> 1); //0 print( 1 <=> 2); //-1 print( 2 <=> 1); //1
Question: Can define accept an array?
Yes, It can. For Example:
define('CLIENTS', [ 'client 1', 'client 2', 'client 3' ]);
Question: What is use of Closure::call() in PHP7?
It is used to temporarily bind an object scope to a closure and invoke it.
For Example:
class A { private $x = 1; } $value = function() { return $this->x; }; print($value->call(new A));
Question: How to import import Classes using single use statement?
Before PHP 7
use com\mytestclass\ClassA; use com\mytestclass\ClassB; use com\mytestclass\ClassC as C;
In PHP 7
use com\mytestclass\{ClassA, ClassB, ClassC as C};
Question: What are Deprecated features in PHP7?
Following are deprecated feature in PHP7.
- Old Style Constructure.
class A { function A() { print('Deprecated'); } }
- Static calls to non-static methods.
class A { function b() { print('Deprecated'); } } A::b();
- password_hash() salt
Question: What extension are removed ?
- ereg
- mssql
- mysql
- sybase_ct
Question: From where I can download PHP7?
http://php.net/downloads.php
Question: How to setup PHP7 with WampServer?
http://www.wampserver.com/en/
Question: What is Class Abstraction?
1. Classes defined as abstract may not be instantiated.
2. Class that contains at least one abstract method must also be abstract.
3. When inheriting from an abstract class, all methods marked abstract in the parent's class declaration must be defined by the child.
4. if the abstract method is defined as protected, the function implementation must be defined as either protected or public, but not private.
Question: Tell me something about Interface?
We use "interface" keyword to create class.
All methods declared in an interface must be public.
To implement an interface, the implements operator is used.
We can include multiple interface while implementing
Question: What are Traits? Give example
Traits are a mechanism for code reuse in single inheritance languages such as PHP.
We can't create instance of a traits
We can create Traits as below:-
trait Hello { public function sayHello() { echo 'Hello '; } }
We can use multiple traits using comma like below
use Hello, World;When two traits have same function, it would conflict but we can fix using insteadof like below
A::bigTalk insteadof B;We can set the visibility of function using "as" like below
use HelloWorld { sayHello as protected; }
We can use one trait from another using "use"
we can also define abstract,static, data members, method
Question: What is Overloading?
Overloading in PHP provides means to dynamically create properties and methods.
These dynamic entities are processed via magic methods one can establish in a class for various action types.
__get(), __set(), __isset() __unset() __call() __callStatic()
Best Related Posts are Following:
- How to detect Mobile Device in PHP? - Simplest way.
- What is Zend Engine in PHP.
- How to Upgrade PHP 5.3 to PHP 5.4 in WAMP Server in window 7.
- How can I upload file asynchronously in php?.
- How to store array in Cookie and retrieve array from cookie.
- get_class_vars PHP Function.
- ob_get_level -Return the nesting level of the output buffering mechanism.
- Difference between WebService and API.
Subscribe to:
Posts
(
Atom
)