Showing posts with label Data storage. Show all posts
Showing posts with label Data storage. Show all posts

Tuesday, March 31, 2015

MongoDB find() and findOne() methods



     In  MongoDB CRUD operation find() and findOne() methods are used to read a documents from the collections. Lets study this methods with example. 

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.




         









Thursday, January 31, 2013

ENCRYPT YOUR IMPORTANT FILES BEFORE SYNCING TO THE CLOUD

As we all know how cloud storage services have become an integrated part of our everyday computer use. Cloud storage gives us flexibility to store our data and to access them from anywhere in the world and also gives many other advantages too. But the main concern raises over here is the security of the data. We always wish that our data must be secured and does not get changed or hacked by others, as we all know how important our data is. So this can be deal with using the Secured Cloud Drive, which encrypts the files using military-grade 256-bit AES encryption prior to sending them your selected cloud drive. This will make your data unreadable to others. It supports almost all your cloud storage services like SkyDrive, Dropbox etc.

Secured Cloud Drive lets you synchronize a shared folder on your computer with the exchange folder on your cloud. The files will be encrypted with the 256-bit encryption layer, so that no one can have access to your files except you. So for this, the software of Secured Cloud Drive is required to download. You can do this by clicking the following link http://www.secured-cloud-drive.com/download/. Once installed, now you have to follow some of the configuration steps that show how the service works.

Select Next and Next option to proceed and in the fifth step you can see the Select Folder option. This option let’s you allow to give the path where your folder is present that you want to share and then click to next to proceed.
Similarly in the sixth step, the application will ask you for your exchange folder. This folder should be present on your cloud drive.
Next you have to specify a password for the encrypted files. The application uses the same password when you download your files to your computer.
Secured Cloud Drive uses a license code for each shared folder. You get a single license for free, but additional licenses have to be purchased for sharing more than one folder. As you receive the license code, enter it to the application and click Next to proceed.
 

Now all you need to do is to store files on the shared folder and they will get automatically encrypted and synced to the exchange folder. This application creates a foldername.exchange directory on the cloud to which the encrypted files are actually moved.
                                                         
The additional folders can be shared by clicking ‘New share’ from the application’s right-click context menu in the system tray. You have also many other options to select such as pause synchronization, exit etc.
                         
This application will keep all your important files safe on your cloud drive.

Monday, December 10, 2012

MTP: The new way to exchange the data


This blog explores the differences between the older Mass storage Class MSC and the newer Media Transfer Protocol MTP methods of sharing embedded device memory when connected to a PC.
Storage is a key component of any embedded handheld device a mobile phone or other convergence devices. To transfer the data stored in these devices, technologies such as USB or Bluetooth are used, the former being more predominant. Generally when the USB shares the memory of a mobile device, it is shared as a drive on the host PC. The USB class used is known as Mass Storage Class (MSC), and it allows you to manage the drive completely like a local hard drive connected to the PC. But in recent Android versions (Ice cream, Sandwich and later), a newer class named MTP Media Transfer Protocol is made default to share mobile memory over USB to a host PC. So what necessitated this change? Let’s take a brief look at the two USB classes to understand why MTP is preferred over MSC.
Before going into advantages of MTP, let us first explore how these two protocols work, with the help of Linux.
An overview of USB MSC
The MSC protocol defines how data exchange can take place between USB host and a USB compliant device. Whenever you see the ubiquitous pen drive for all your data transfer activities, MSC is the underlying protocol. USB devices using the MSC class are equivalent to an external hard drive connected to host. These devices can be used just like in-PC drives, to drag and drop files. Thus, the USB host can interact with different flash/hard drives without having any knowledge about the underlying storage system.
Linux USB MSC architecture
Figure 1below shows the block level architecture when an MSC device is connected to a standard Linux host. The Linux device’s MSC architecture consists of two parts: the storage subsystem and the USB subsystem. In the Linux framework, the Virtual File System (VFS) layer is used to abstract the storage and the USB layers. The gadget driver, being USB controller specific, collects the USB transfers and identifies to which function the transfer belongs (e.g. the Ethernet packet, the MSC packet, etc). If it is an MSC packet, the gadget driver sends the packet mass storage driver. Inside the class driver, the SCSI commands are decoded, and appropriate storage operations are done using the VFS layer. SCSI is a standard for the transfer of data between two devices. The entire blocks are implemented in kernel space.
Fig. 1 Linux USB MSC Architecture
On the host side, the USB core drivers detect the USB device and expose it as a block device. The data is transferred to the block layer as SCSIcommands, the data is transferred to the block layer as SCSI commands, with the help of the storage driver.
An overview of the Media Transfer Protocol (MTP)
MTP was introduced by Microsoft to enable data exchange between a USB host (initiators) and devices (responders) with ‘intelligent ‘storage capabilities (those with some sort of user interactivity). These include smartphones, tablets and portable audio players. ‘Media’ in Media Transfer Protocol does not just mean audio/video; it encompasses all binary data, including text files. Devices supporting MTP come up as ‘portable device’ and not a drive as in USB MSC. All the content (songs, images, videos) on devices are represented by objects, and object handles are used in order to reference a logical object on the device. Once the device is connected to the USB host, enumeration takes place, and all associated metadata, such as the file creation, the time of modification, size, folder details, etc, are passed to the host PC. After this, data exchange can begin.

Fig. 2 Architecture of MTP
Android implementation of MTP
In Linux, sysfs is an interface used for communication between user space and kernel space. Figure illustrates the block-level architecture when an MTP device is connected to a standard host. The MTP implementation on the device side is divided across user space and kernel space.User space components: The mtp daemon (mtpd) runs in the JVM (Java Virtual Machine) of Android. It loads and calls the USB Device MTP Library via JNI (Java Native Interface). The USB device MTP Library takes care of decoding and responding to MTP commands.Kernel space components: The USB device MTP Function Driver handles the MTP class-specific control requests like opening or closing the session as per the user’sinstructions. It also controls reading/writing of files from the storage media through the Virtual File System.   On the host side, the USB core drivers communicate with the USB device. Applications like Windows Media Player on Windows use the libmtp library to communicate with device. Based on the requests from the applications, mtpd on the device would respond using the USB drivers.
The advantages of MTP   
From both the architectures, you can see that MSC works on SCSI commands, and the host has unrestricted access to the device. The device cannot modify the data without releasing its connection from the host, if mounted. If the device is given permissions to modify the data when there is a connection with the host, there are chances of corrupting the data, or even the file system. That is why when you mount an SD card of an Android device to a PC, you cannot access the SD card using the Android device until you unmount it from the PC. MTP has a solution to this problem. It manages the files, unlike MSC, which manages storage. The media player on the host reads and writes entire files on the device.With MTP, Windows Media Player has an option to sync media content on the PC and the device. You can even customize the data content for the sync options based on the ratings etc. With MISC, this can be achieved only with special applications.     Unlike MSC, MTP enables the monitoring of device initiated events, and the changes in device properties.                                                                       
MTP does not allow the transfer of unsupported file formats, unlike mass storage, where the user needs to check for compatibility after the file transfer.            
Lastly, MSC and MTP represent two efficient data exchange methods. While MSC has been the de-facto standard followed until the recent past, it fails to address the needs posed by modern-day intelligent storage devices. While flash-based devices will continue to use MSC, we will see more and more portable devices with hard drives switching over to MTP. However, it is always the user’s prerogative to choose between the free way or the safe way to manage data i.e., whether to use MSC or MTP.