Sandip Foundation's Students' Blog.
Official blog by Students of Sandip Foundation's Engineering Students, Nashik (INDIA)
Tuesday, February 23, 2016
Monday, September 7, 2015
Installing and Using Ruby Interactive Shell on Windows
Ruby is dynamic,interpreted, object oriented programming languages which is one of the easiest programming language to learn and with Rails its just might be the best web development option at the moment. Ruby intsallation is pretty much simple in windows, Linux and you don't have to install Ruby on Mac. It already has Ruby installed in it.
On ruby shell single number evaluates itself. We can perform simple arithmetic operations the ways show above screenshot. Strings also evaluate to them self, We can perform concatenation operation between two strings using '+' operator as shown below :
We can write more complicated expressions in ruby shell. We can create functions for example square function in bellow example. Here I wrote my own user define "sqr" function to find square of a number.
If you have good understanding of function you not even have to write return statement. lets consider following function for addition of two numbers. In which I wrote add method for addition of two numbers when next time I write add(2,2) it performs addition of these two numbers which is 2+2=4.
Step by step guide to install Ruby on your PC:
- Go to Ruby programming language homepage: https://www.ruby-lang.org/en/
- Click downloads
- Click on Installation-->click on RubyInstaller(Windows)-->Ruby installer-->Download
- Select the top selection there that will be the current version of Ruby
- Click save file. let it download
- Now double click the file-->accept license agreement-->Install-->finish.
Using Ruby Interactive Shell
The interactive shell or just a shell allows us to type Ruby statements or expressions at the command line and gives immediate result. So open the command prompt and navigate to the folder where Ruby is installed and type "irb".
On ruby shell single number evaluates itself. We can perform simple arithmetic operations the ways show above screenshot. Strings also evaluate to them self, We can perform concatenation operation between two strings using '+' operator as shown below :
We can also store data in variables and use it later as shown in below "greet' is variable which stores value "good morning". After typing good morning it returns "good morning".
We can also concatenation "greet" with other value
We can write more complicated expressions in ruby shell. We can create functions for example square function in bellow example. Here I wrote my own user define "sqr" function to find square of a number.
If you have good understanding of function you not even have to write return statement. lets consider following function for addition of two numbers. In which I wrote add method for addition of two numbers when next time I write add(2,2) it performs addition of these two numbers which is 2+2=4.
Wednesday, August 12, 2015
Tuesday, March 31, 2015
MongoDB find() and findOne() methods
1. find() :
The most basic operation to query documents out of the database is called find(). MongoDB find() method returns all documents present in the database.
For example, Here I have student database and collection name is grades which has 800 documents. After executing this query it returns first 10 documents and it ask for next 10 documents. If you want more documents type "it" next 10 documents will get display.
find() method can take some arguments. You can filter result by adding search criteria. For example in "grades" collection there are "homework","quiz" and "exam " type of documents. If I want only "exam" type . The query will be db.grades.find({''type'' :''exam''}).
We can also add multiple fields in criteria but both the criteria should match. Like here I have selected students with type :exam and you can also include and exclude fields if you want by making field name true or false, here I excluded object id field.
2. findOne():
This method also retrieves the data but it returns only one document at a time. Lets see following example fineOne() without argument returns very first document from the collection.
We can also add criteria in findOne() method like find() method. In following example only document with the "student_id" : 112 is return as specified in criteria.
Labels:
10gen,
basic shell,
big data,
CRUD,
data,
Data storage,
Database,
find(),
fineOne(),
method,
mongo,
mongo shell,
mongod,
mongodb,
mongodb database operations,
open source,
open soure project,
read
Sunday, September 21, 2014
Saturday, September 20, 2014
MongoDB CRUD Operations
MongoDB CRUD stands for Create, Read, Update, Delete. MongoDB provides rich semantic to communicate with the database. MongoDB CRUD operations are much similar to SQL create,select,update and delete operations. If you already work with SQL you will find it very easy to understand and if your not then still you will find it very easy! OK, before moving forward to CRUD operation we have to understand how MongoDB stores data. As we know MongoDB is document oriented database it stores the data in the form of documents.
So no rows and columns. It uses JSON(JavaScript Object Notation) like format to store data. Formally, MongoDB documents are BSON documents. BSON is a binary representation of JSON with additional type information. following image is example of MongoDB document.
In MongoDB there are collections instead of table. In MongoDB database contains number of collections MongoDB stores all the documents in collection. Collection is a group of related documents that have a set of shared common indexes.
We will perform the tasks in following order :
- Create
- Insert
- Read
- Update
- remove
1. Create:
lets start from creating database in MongoDB. Now what you have to do is just enter following command on mongo shell,
Syntax:
use databasename
Example:
use blogdata
Database is not created unless you not inserting documents in it.
2. Insert:
To write into database following syntax is used,
Syntax:
db.collectionname.insert({ document to be inserted});
You can use any other folder name instead of "db" if you want.You don't have to create collection separately. It will automatically get created.
example:
To see the document that you have inserted run this command "db.collectionname.find()", "collectionname" should be the same which you have used earlier to insert document.
3. Read:
To read data from the database following command is used,
Syntax:
db.collectionname.find();
By using this command documents will get displayed, you can be more specific by writing some criteria in find(), by default it will display all documents that contains in collection. But if you want to get specific document then Mongo provides way to write more optimized query you can use :
- Limit the cursor means you can limit the number of result you get which matches criteria.
- Can add projections means you can specify which fields you want in result.
- Can add query criteria
Example:
This query returns documents in which age is greater than 18. It will display only name and address field because it is specified as "1" if field is "0" then mongo does not display that fields in result. Look at following SQL query which gives same result as mongo query for more better understanding.
4. Update:
Update operation is used to modify the documents,
Syntax:
db.collectionname.update({ criteria})
Example:
Following query will update the document field "status" as "A" where field "age" has value greater than "18".
Following SQL query gives the same result as mongo.
5. Remove:
Remove operation is used to delete documents from database,
Syntax:
db.collectionname.remove({criteria})
Example:
Following query will remove the documents where "status" field is "D".
See the SQL query for same operation,
Labels:
BSON,
CRUD,
Database,
delete,
JSON,
mongo,
mongo shell,
mongod,
mongodb,
mongodb database operations.create,
mongodb features,
NoSQL,
remove,
shell,
types of nosql,
update
Subscribe to:
Posts (Atom)