Search

Overview of Modules in Node.js

Node.js is an open source, server-side runtime environment which runs on various platforms like Windows, Linux, Unix and other operating systems. Node.js is built on JavaScript engine and provides ability to build scalable applications. The runtime environment is event-driven and provides asynchronous programming which is memory efficient. Node.js is useful in generating dynamic page contents as it eliminates the need for the wait to open and close files and continues with the next request. We can also use Node.js to modify data in our database. In other languages, it’s usually better to structure our application code and break it into small pieces. However, in ode.js, we can write all our application code in one index.js file, irrespective of the complexity of our application, and the node.js interpreter will not cause issues. But, if we have very complex application, it would be better to divide our application code into small modules and then combine them into a cohesive application. Introduction to Node.js Modules Node.js modules are the different functions which can be reused time and time again. They can be organized into single or multiple JavaScript files in the same or different folders. Each file is treated as a single module. They can also be considered as JavaScript libraries. Every module has its own context and does not interfere in the working of another module. Together, these modules help to run the application.  Before we deep dive into types of modules, let’s take a quick example of creating a simple module.  const average = (a, b) => {return a + b;}; const output = average (2, 3)console.log(output)The above module will calculate the average of two numbers and display the output. Types of Node.js Modules Built-in Modules When we install node.js, several lightweight modules are automatically created, which provide bare minimum functionalities.  These modules are compiled into the node.js binary. They are also referred to as core modules and located in the lib folder. Below are few of the built-in modules in node.js   ModuleCommentsurlUsed for url parsing and resolutionpathIt is used to deal with file paths using methodsfsIt is needed to work with I/OutilIt includes utility functions needs by programmers.httpIt is used to create http server using classes, methods and events.These modules are used in our application code as reference. The code of these modules are not part of our program as they work as libraries. They are always loaded if their identifies is passed to require().  Let’s see an example:var URL = require('url').URL;Here require(‘url’) is what gives us access to url module. The definition of url module is not seen to us. We just need to understand when and how to use it.  Built-in functions have methods and classes which can be used when we require() the module.  For example:var http = require('http');   http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/html'});   res.end ('Welcome to Node.js Modules!');   }).listen(8080);Here, we use the http built in module using the require(‘http’). Once we load the http module, its classes and functions like createServer can also be used.  External Modules Node.js has a huge open source community which really boosts its ecosystem. People from around the globe contribute to the node.js community, which provides access to various modules other than the built in modules. These modules are created to solve specific problems in specific environments and then open sourced for the benefit of others. Since these modules are not part of the library, they cannot be used directly using the require unless we first install the codebase containing the module locally; once this is done, they can be integrated to our codebase. External modules are also known as third party modules and require a package manager that maintains all the modules so that they can be accessed with ease. By default, node.js uses NPM [node package manager) package manager for JavaScript runtime environment. NPM is primarily used to install and maintain external modules in node.js application; we can install the external modules which are needed for the application using NPM. Custom Modules Built in and External modules are provided by others based on their needs. However, there might be cases where you need to build your own module for your application.  Let’s create a module of our own named mydiffreturn Math.diff() * (max - min); } exports. between1and10 = function () { return getdiff (1, 10); };We will put this code in a separate file called mydiff.js which provides helper function that returns a difference of two numbers. This file can provide attributes to the outer world via exports, then index.js can use the exported functionality.   Below is the content of index.jsvar mydiff = require('./mydiff.js'); console.log(mydiff.between1and10());require () will again come into play by making the attributes of local mydiff module available. Module can also allow hiding to hide the functionality of the module which is not needed outside of the module. This can be done simply by not exporting the functionality via exports. In such case even though we will have mydiff.js file specified in index.js it will not be able to access the non-exported function and fail with the following error.  TypeError: mydiff.getdiff is not a functionThis way, we can keep our codebase more organized by hiding the implementation details in a module and exposing only those parts which will be used by other parts of the codebase.  Module Caching When the modules are first loaded, they are cached. This means every call to the require () will get the same object returned for multiple calls if the call is resolved to the same file. This is an important feature as it allows us to load the transitive dependencies for returning partial objects. Module caching is done in an object in a key-value pair and then we can reference the objects using the cache (require.cache). If we delete any key from this object, then we need to reload the module on next require () call. Caching Modules also have some caveats as the modules are cached based on their filenames. If a module is resolved to a different filename based on the location of calling module it is not guaranteed that require () will always return the same object. Also, in case of different case-insensitive file systems, different resolved file systems points to the same file. In such a case, again, cache will treat them as separate which will result in reloading the module multiple times. For example, require (‘. /mydiff’) and require (‘. / Mydiff’) would result in two different objects. Stateful & Stateless modules If a node.js module exposes an instance of some stateful object like db connection or socket etc., it is stateful module. Whereas, if a module exposes stateless entities like classes, methods etc., then it is known as stateless module. If an application codebase uses stateful module, we should follow the singleton pattern so that all other modules requiring stateful module access the same instance. Due to the concept of CommonJs system we don’t have to explicitly wrap our stateful module in Singleton pattern. The first time we use the module, it will be cached for the subsequent require as while caching, node.js uses instance package address as a key. Stateful modules should be used with more caution than stateless modules if used in the tightly coupled architecture. Module Dependencies Any component or piece of information that is needed for the working of the module is regarded as dependency, but the first thing that comes to mind while thinking about the dependencies of node.js is the content of the node_modules folder. From database connection instance to string with file path can be considered as dependency. In a broader classification, dependencies are divided as ‘hardcoded dependency’ and ‘injected dependency’. If you hardcode the name of the dependency inside the module using a require function in the wiring pattern, it is referred to as ‘hardcoded dependency’. If the name of dependency is instead provided as input by external entity, then it is known as ‘dependency injection’. Let’s see some differences between hardcoded dependency and dependency injection. Hardcoded DependencyDependency injectionThey are intuitive and easy to understand.Offer higher reusability.Easy to debug.Difficult to debug.Offer less flexibility as they are tightly coupled.Dependencies are wired at runtime.Unit testing is harder since dependencies are hardcoded.Unit testing is easyConclusion To understand how node.js modules work, we need to know the various functionalities it offers. With this objective in mind, we first looked at the different types of node.js modules. We then explored built in modules, looking at different types of modules and examined what they offer and the advantages of having these modules.  We then saw External modules and walked through how they can be included in our codebase, including how the module code could be hidden if we so wished. Finally, we saw custom modules, their benefits and how to use them effectively. We examined how modules can be cached in modules providing us with performance gains by avoiding reload several times, while also going through some caveats we should be aware of.  We also saw how modules can be stateful and stateless and where both can fit in. Finally, we explored the module dependencies and few differences between them which helps us choose among them as per the need of the application.
Overview of Modules in Node.js
KnowledgeHut
Rated 4.0/5 based on 15 customer reviews
KnowledgeHut

KnowledgeHut

Author

KnowledgeHut is an outcome-focused global ed-tech company. We help organizations and professionals unlock excellence through skills development. We offer training solutions under the people and process, data science, full-stack development, cybersecurity, future technologies and digital transformation verticals.

Posts by KnowledgeHut

Overview of Modules in Node.js

Node.js is an open source, server-side runtime environment which runs on various platforms like Windows, Linux, Unix and other operating systems. Node.js is built on JavaScript engine and provides ability to build scalable applications. The runtime environment is event-driven and provides asynchronous programming which is memory efficient. Node.js is useful in generating dynamic page contents as it eliminates the need for the wait to open and close files and continues with the next request. We can also use Node.js to modify data in our database. In other languages, it’s usually better to structure our application code and break it into small pieces. However, in ode.js, we can write all our application code in one index.js file, irrespective of the complexity of our application, and the node.js interpreter will not cause issues. But, if we have very complex application, it would be better to divide our application code into small modules and then combine them into a cohesive application. Introduction to Node.js Modules Node.js modules are the different functions which can be reused time and time again. They can be organized into single or multiple JavaScript files in the same or different folders. Each file is treated as a single module. They can also be considered as JavaScript libraries. Every module has its own context and does not interfere in the working of another module. Together, these modules help to run the application.  Before we deep dive into types of modules, let’s take a quick example of creating a simple module.  const average = (a, b) => {return a + b;}; const output = average (2, 3)console.log(output)The above module will calculate the average of two numbers and display the output. Types of Node.js Modules Built-in Modules When we install node.js, several lightweight modules are automatically created, which provide bare minimum functionalities.  These modules are compiled into the node.js binary. They are also referred to as core modules and located in the lib folder. Below are few of the built-in modules in node.js   ModuleCommentsurlUsed for url parsing and resolutionpathIt is used to deal with file paths using methodsfsIt is needed to work with I/OutilIt includes utility functions needs by programmers.httpIt is used to create http server using classes, methods and events.These modules are used in our application code as reference. The code of these modules are not part of our program as they work as libraries. They are always loaded if their identifies is passed to require().  Let’s see an example:var URL = require('url').URL;Here require(‘url’) is what gives us access to url module. The definition of url module is not seen to us. We just need to understand when and how to use it.  Built-in functions have methods and classes which can be used when we require() the module.  For example:var http = require('http');   http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/html'});   res.end ('Welcome to Node.js Modules!');   }).listen(8080);Here, we use the http built in module using the require(‘http’). Once we load the http module, its classes and functions like createServer can also be used.  External Modules Node.js has a huge open source community which really boosts its ecosystem. People from around the globe contribute to the node.js community, which provides access to various modules other than the built in modules. These modules are created to solve specific problems in specific environments and then open sourced for the benefit of others. Since these modules are not part of the library, they cannot be used directly using the require unless we first install the codebase containing the module locally; once this is done, they can be integrated to our codebase. External modules are also known as third party modules and require a package manager that maintains all the modules so that they can be accessed with ease. By default, node.js uses NPM [node package manager) package manager for JavaScript runtime environment. NPM is primarily used to install and maintain external modules in node.js application; we can install the external modules which are needed for the application using NPM. Custom Modules Built in and External modules are provided by others based on their needs. However, there might be cases where you need to build your own module for your application.  Let’s create a module of our own named mydiffreturn Math.diff() * (max - min); } exports. between1and10 = function () { return getdiff (1, 10); };We will put this code in a separate file called mydiff.js which provides helper function that returns a difference of two numbers. This file can provide attributes to the outer world via exports, then index.js can use the exported functionality.   Below is the content of index.jsvar mydiff = require('./mydiff.js'); console.log(mydiff.between1and10());require () will again come into play by making the attributes of local mydiff module available. Module can also allow hiding to hide the functionality of the module which is not needed outside of the module. This can be done simply by not exporting the functionality via exports. In such case even though we will have mydiff.js file specified in index.js it will not be able to access the non-exported function and fail with the following error.  TypeError: mydiff.getdiff is not a functionThis way, we can keep our codebase more organized by hiding the implementation details in a module and exposing only those parts which will be used by other parts of the codebase.  Module Caching When the modules are first loaded, they are cached. This means every call to the require () will get the same object returned for multiple calls if the call is resolved to the same file. This is an important feature as it allows us to load the transitive dependencies for returning partial objects. Module caching is done in an object in a key-value pair and then we can reference the objects using the cache (require.cache). If we delete any key from this object, then we need to reload the module on next require () call. Caching Modules also have some caveats as the modules are cached based on their filenames. If a module is resolved to a different filename based on the location of calling module it is not guaranteed that require () will always return the same object. Also, in case of different case-insensitive file systems, different resolved file systems points to the same file. In such a case, again, cache will treat them as separate which will result in reloading the module multiple times. For example, require (‘. /mydiff’) and require (‘. / Mydiff’) would result in two different objects. Stateful & Stateless modules If a node.js module exposes an instance of some stateful object like db connection or socket etc., it is stateful module. Whereas, if a module exposes stateless entities like classes, methods etc., then it is known as stateless module. If an application codebase uses stateful module, we should follow the singleton pattern so that all other modules requiring stateful module access the same instance. Due to the concept of CommonJs system we don’t have to explicitly wrap our stateful module in Singleton pattern. The first time we use the module, it will be cached for the subsequent require as while caching, node.js uses instance package address as a key. Stateful modules should be used with more caution than stateless modules if used in the tightly coupled architecture. Module Dependencies Any component or piece of information that is needed for the working of the module is regarded as dependency, but the first thing that comes to mind while thinking about the dependencies of node.js is the content of the node_modules folder. From database connection instance to string with file path can be considered as dependency. In a broader classification, dependencies are divided as ‘hardcoded dependency’ and ‘injected dependency’. If you hardcode the name of the dependency inside the module using a require function in the wiring pattern, it is referred to as ‘hardcoded dependency’. If the name of dependency is instead provided as input by external entity, then it is known as ‘dependency injection’. Let’s see some differences between hardcoded dependency and dependency injection. Hardcoded DependencyDependency injectionThey are intuitive and easy to understand.Offer higher reusability.Easy to debug.Difficult to debug.Offer less flexibility as they are tightly coupled.Dependencies are wired at runtime.Unit testing is harder since dependencies are hardcoded.Unit testing is easyConclusion To understand how node.js modules work, we need to know the various functionalities it offers. With this objective in mind, we first looked at the different types of node.js modules. We then explored built in modules, looking at different types of modules and examined what they offer and the advantages of having these modules.  We then saw External modules and walked through how they can be included in our codebase, including how the module code could be hidden if we so wished. Finally, we saw custom modules, their benefits and how to use them effectively. We examined how modules can be cached in modules providing us with performance gains by avoiding reload several times, while also going through some caveats we should be aware of.  We also saw how modules can be stateful and stateless and where both can fit in. Finally, we explored the module dependencies and few differences between them which helps us choose among them as per the need of the application.
Rated 4.0/5 based on 15 customer reviews
6517
Overview of Modules in Node.js

Node.js is an open source, server-side runtime ... Read More

The ITIL Framework and It’s Processes

You’ve got ITIL® questions. We’ve got ITIL answers. Recently, a group of learners, due to complete their engineering degrees in computer science caught up with John Dell, one of our expert ITSM trainers and authors, seeking advice on careers in ITSM. This blog is an account of the conversation which will serve ITIL aspirants well. The learners opined that they were not very keen on programming and would like to explore what other options exist in the IT sector. They were about to graduate and were not sure there is much opportunity outside programming in IT. John clarified that firstly, the IT sector does not revolve only around software development. The IT industry is vast and presents plenty of opportunity. He suggested they start by carrying out a quick SWOT analysis for themselves.  Majority of the learners cited that communication, good analytical and testing skills and leadership skills were their strengths;incidentally, coding and design were not particularly strengths for this group. The group recognized that IT support and the IT service industry would open up several opportunities, while programming and core software development were not areas that appealed to them. Based on this basic SWOT analysis, John suggested that the students considerjobs related to Service management. Jumping into whatITIL is all about and how it couldpropeltheir career.  IT Management mainly involves Software Development & Management, IT Infrastructure Management, and IT Service Management. The ITILFramework refers to set of best practices, guidelines, methodologies designed by industry experts to align their IT Services with customer and business strategic goals. So, this framework provides uniform and consistent guidelines to all IT industries to define their IT Service Management processes.  Why is there a need for a consistent framework? When asked whether each IT companycan come up with their own framework and design for IT service management, John answered that they actually can. He further elaborated with an illustration -  Company A provides support to Company X and Company B provides support to Company Y. Here, A and B are Service providers and X and Y are service consumers. They have not adhered to any service management framework.  Both service providers, A and B, have unknowingly made many mistakes and faced lots of challenges in providing support to their consumers, X and Y.  After a couple of years, once the project is completed, A and B have not exchanged notes, nor learnt from each other’s mistakes. Six months down the line, B commits the samemistakes that A earlier had and vice versa. In such a scenario, would service consumers X and Y ever come back to A and B again? Not likely. When mistakes repeat,service consumersor customers will not be happy and may not return to with the project again. To avoid such a scenario, what such companies could do is to connect with each other and sharelessons. Such an initiative would avoid many bottlenecks and arrest many recurring challenges. John explained that companies, understanding the importance of consistent process, have embraced lessons from the industry and continually improvise their processes for better customer experience. While it may not be feasible to connect with every other company and collect their lessons and best practices in real time, not with standing that companies may or may not share that information, there is a need for a common forum or entityto collect best practices and lessons across the IT industry and formulate aframework. Such a framework formulated for the IT Service industry is called the ITIL framework. Why is this framework called ITIL? ITIL stands for Information Technology Infrastructure Library. When asked why it was referred to as a ‘Library’, John explained that it is a set of practices for Information Technology Service Management (ITSM) that focuses on aligning IT services with the needs of the business.  As it is a set of practices best practices and lessons from the service industry, it is referred to as a “library”.  Significance ofITILin theService Industry Johnwent on to explain that there were plenty of reasons for the ITIL framework: ITIL framework helps to align the IT solutions with business strategic goals  It helps to set the realistic, achievable and predictable service goals  It ensures efficient service delivery and improves customer satisfaction  It reduces costs through improved utilization of resources  It defines consistent IT roles and improves communication through standardized terminology It improves planning and continual improvement due to regular measurement and monitoring What is meant by continual improvement? John addressed the question with a use case: Company A is the Service Provider and Company X is the Service consumer.  Company A and Company X are in legal contractual agreement. Company A agrees to provide N services to Company X for the next 2 years. One of the agreed services is to resolve all High priority incidents within 4 hours. After a year of experience, Company A (Service Provider) becomes very good knowledge in resolving incidents within 2 hours and this has been verified as well.  Now, Company A (Service Provider) submits a proposal to Company X (Service Consumer) to improvise the High priority incident resolution time by 2 hours instead 4 hours. The contractual document is amended. Company X (Service consumer) agrees to pay an additional amount for the improvisation of service to Company A (Service Provider). This is a good example of continual improvement.  Continual improvement results in improvising service will always increase the customer satisfaction index, says John. History of ITIL In the year 1989, the UK Government’s Central Computer and Telecommunications Agency (CCTA) developed the first version of ITIL to unite IT systems in an efficient and cost-effective way.  Collecting best practices from all government agencies and private sector companies across Europe, the CCTA came up with an initial standard framework. ITIL soon grew to a 30-volume catalogue, providing a collection of all IT best practices that focused on and catered for client and business needs. In the year 2000, CCTA change into OGC (Office of Government Commerce, UK). The same year, Microsoft also adopted ITIL as the foundation for developing their Microsoft operations and framework (MOF). This version was focused on making ITIL more accessible and arranged the 30-volume framework into nine related categories.  In the year 2007, ITIL was expanded and reorganized as an IT service management lifecycle, known as ITIL Version 3 (ITIL V3).  Thisversion covers the initial conception, development, transition, operations, and improvement of a service.  ITIL V3 views the activity of managing service as a lifecycle, which is a shift in focus from the individualized process/function view of the previous version.The service lifecycle concept has further evolved since.  In the year 2011, AXELOS released a revision of ITIL that resolved errors and inconsistencies with V3. This is the updated version of the 2007, referred to as ITILv3 updated. In this version,the ITIL service lifecycle contains 5 stages:  ITIL Service Strategy,  ITIL Service Design,  ITIL Service Transition,  ITIL Service Operation and  ITIL Continual Service Improvement.  This forms the basis for all ITIL best practices across the globe. Since 2013, ITIL has been owned by AXELOS Ltd – a joint venture between Capita Plc and the British Government’s Cabinet Office. In the year 2019, due to the Industry 4.0 revolution, the current version of ITIL was launched. V4 has more practical guidance on how to use ITIL in an organization which embraces digital journey. This makes it easier for organizations to align ITIL with DevOps, Agile, and Lean work methods. With V4, ITIL adopted more of a holistic philosophy towards service management, making it broader and more inclusive for the modern IT environment. Having developed a good understanding of the evolution of ITIL, the students learnt about how the best practices which originated from a few European companieswere continuously improvised and revised tonow become a global acceptable Service management framework across the globe. How ITIL works The students now wanted to go deeper and asked how ITIL could help the organization to achieve its strategic goals. John explained that following ITIL practices helps organization achieve their strategic goals by: Ensuring quality of IT services meetsService consumer’s expectations and needs EnsuringService consumer can use IT services whenever and wherever they are needed Ensuring organizations can improve Customer satisfaction by building and maintaining positive business relationships Ensuring that organizations maximize value for money from their service providers Allowing organizations to benchmark their IT services and maximize ROI Allowing organizations to demonstrate and quantify the actual value of the services they provide Allowing organizations to forecast, influence, and respond to demand IT services in a cost-effective manner depending on fluctuating demand situations Allowing organizations to minimize IT service disruption Stages of ITIL and the purpose of each stage By now, the students were very keen and eager to know about the different lifecycle stages defined in ITIL V3 and its purpose. John went on to explain that ITIL has five stages. The following table helps explain each stage and its purpose:S.NoITIL StagesPurpose1Service StrategyThe Service Strategy stage provides guidance on how to design, develop, and implement IT Service Management. This is the core of the Service Lifecycle. This phase mainly focuses on understanding and defining the market. Also defines the needs of the customers2Service DesignIn the Service Design stage, strategies generated in Service Strategy stage are turned into action. Services and processes are designed, and plans are implemented to have a better service management.3Service TransitionThe Service Transition stage ensures that the new changes and modifications are efficiently incorporated in the service lifecycle without disrupting the other existing services or processes. It is carried out in a well-coordinated manner using cost-effective measures and resources. Through service transition, the design built is tested and implemented in the lifecycle in a productive manner4Service OperationThe Service Operation stage provides guidance on day-to-day business operations. The goal is for the IT department to keep things running smoothly, reliably, efficiently, and cost-effectively. The activities and processes in this phase ensure that services are delivered to customers at the agreed Service level agreement with minimal interruptions and disruptions. Service Operation focuses on providing value to both service consumer and the service provider.5Continual Service ImprovementThe Continual Service Improvement stage focus on improving the current service to the Service consumers. Continual Service improvement focus on progressive monitoring and controlling of services. Key performance indicators must be in place to determine whether the service is running optimally, and the service owner must ensure that the service complies with the strategic targets linked to the IT serviceJohn went on to explain that the outcomes of the Continual Service Improvement become the inputs for Service Strategy. Identified improvements will help to revise the strategic goals and targets.  Explaining what was meant by Key Performance Indicator, John defined it as a quantifiable measurement for measuring any strategic goal. This is generally agreed between Service consumer and Service Customer in the legal contract, he added. The difference between ITIL®V3 and ITIL®4  Digging deeper into the difference between ITILv3 and ITIL4, John explained that ITIL4 was the latest version. The two may need to be prioritized depending on the case, he pointed out.  S.NoITILv3ITIL41IT defines life cycle approachIt defines Service Value system-based approach2This version does not talk about 4-dimension model.This version emphasises the importance of 4-dimensions for a holistic service management.3ITIL V3, with its 26 service lifecycle processes, functions and other guidance arguably also describes how the components and activities in the organization work together.ITIL 4 and the Service value system take a more holistic approach, providing organizations with a flexible operating model that supports different work approaches. ITIL 4 presents 34 practices as "sets of organizational resources designed for performing work or accomplishing an objective".4There are no guiding principles under ITILv3The ITIL 4 guiding principles are universal recommendations that can guide organizations in many situations, such as "work holistically" and "keep it simple and practical".5ITIL V3 covers governance under service strategyThe governance component of the ITIL 4 service value system is about directing and controlling the organizationWhat are the different certifications available in ITIL? Explaining the available certifications in ITIL, John elaborated using the following table to help the students to understand the different certifications under ITIL.  (Source: Axelos). S.NoLevelsPurpose1ITIL 4 Foundation LevelThe ITIL 4 Foundation certification is designed as an introduction to ITIL 4 and enables candidates to look at IT service management through an end-to-end operating model for the creation, delivery and continual improvement of tech-enabled products and services.2ITIL 4 Managing ProfessionalThe Managing Professional (MP) stream provides practical and technical knowledge about how to run successful IT enabled services, teams and workflows.3ITIL 4 Strategic LeaderITIL 4 Strategic Leader demonstrates that the you have a clear understanding of how IT influences and directs business strategy.4Master LevelTo achieve the ITIL Master certification, you must be able to explain and justify how you have personally selected and applied a range of knowledge, principles, methods and techniques from the ITIL Framework and supporting management techniques, to achieve desired business outcomes in one or more practical assignments.Getting started Concluding, John summarized that to get started all one needs to do is to talk to professionals to understand how the work they do contributes to creating value for customers. If everybody thinks about what they do in these terms, then the next step will be much easier. The IT world we live in is becoming more and more service based by the day and there is great opportunity. Industry leaders have seen ITIL in action and have bought into it. Most major global corporations run their services on ITIL®, and such IT professionals are in great demand. 
Rated 4.0/5 based on 15 customer reviews
7028
The ITIL Framework and It’s Processes

You’ve got ITIL® questions. We’ve got ITIL an... Read More

How to Update Document in MongoDB

MongoDB provides the update() method to update the documents of a collection. To update only the specific documents, you need to add a condition to the update statement so that only selected documents are updated. In this article, we will understand how to update a document in MongoDB using the update() method, save () method, updateOne() method and updateMany() method with examples for each. We will also look at the differences between each of these methods. Updating Single document Syntax: db.collection.update(query, update, options) Use the update method  Specify the condition to be used to update the document. In the below example, we need to update the document which has the Employee id as 100. Use the $set operator to update the values  Choose the Field Name that needs to be updated and enter the new values accordingly –  Employee_Name =”Daniel Morales”db.Employees.update( {"Emp_ID" :100}, {$set:{"Employee_Name" :"Daniel Morales"}}); WriteResult({"nMatched": 1,  "nUpserted: 0, "nModified":1 })Updating Multiple documents Syntax: db.collection.update(query, update, options) For updatingmultiple documents at the same time in MongoDB, we need to use the multi option or else by default only one document is updated at a time. The below example shows how to update many documents. In this example, we are going to first find the document which has the Emp_ID id as "1" and then change the Emp_ID from 1 to 21 and Employee_Name to “Nandan Kumar”. Use the update method  Specify the condition which you should be used for updating the document. In the below example, we need to update the document which has the Employee id as 1. Use the $set operator to update the values  Choose the Field Name(s) that needs to be updatedand enter the new values accordingly – Employee_Name =”Nandan Kumar” Emp_ID = 21db.Employees.update({ Emp_ID : 1},{$set :{"Employee_Name" : "Nandan Kumar"," Emp_ID" : 21}})MongoDB save() Method  The db.collection.save() method is used to update an existing document or insert a new document Syntax: db.collection.save() db.Employees.save( {Emp_ID : 21000 , Employee_Name : "Anshu", Salary:20000 } ); WriteResult({“ nInserted" : 1 })The save() method returns a WriteResult object which contains the status of the insert or update operation. During the insert, the shell will create the _id field with a unique ObjectId value, as verified by the inserted document:db.Employees.find(); {"_id" : ObjectId("5da78973835b2f1c75347a83"),"Emp_ID" : 21000 , "Employee_Name" : "Anshu", "Salary":20000 }In the below example, save() method performs an insert since the document passed to the method does not contain the _id field so it creates a new document . Note -  If the document doesn’t contain an _id field, then the save() method calls the insert() method. db.Employees.save({_id:2400, Emp_ID : 21000 , Employee_Name : "Anshu", Salary:20000 } ); WriteResult({"nMatched": 0,  "nUpserted: 1, "nModified":0,”_id”:2400})The save() method performs an update with upsert:true since the document contains an _id field:  db.Employees.save({_id:2400, Emp_ID : 21000 , Employee_Name : "Anshu", Salary:20000 } ); WriteResult({"nMatched": 1,  "nUpserted: 1, "nModified":0 })Note -  If the document already contains an _id field, then the save() method is equivalent to an update with the upsert option set to true and the query predicate on the _id field. Updating Single and Multiple Values in MongoDB documents by using methods  -updateOne, updateManywith examples : MongoDB updateOne() method This method updates a single document within a collection matching the filter or condition. Syntax The syntax of updateOne() method is − db.collection.updateOne(, ) Example> db.Employees.updateOne( {First_Name: 'Nandan'}, { $set: { Age: '30',e_mail: 'nandan@gmail.com'}} ) { "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 0 }MongoDB updateMany() method The updateMany() method updates all the documents within a collection based on the filter or condition . Syntax : The syntax of updateMany() method is − db.collection.updateMany(, ) Example>db.Employees.updateMany(  {Age:{ $gt:"25"}},  { $set:{Age:'12'}}  )  {"acknowledged":true,"matchedCount":2,"modifiedCount":2}Using the find command, you can retrieve the contents of the documents:> db.EmpDetails.find() { "_id" : ObjectId("6fd6636870fb13eec3963bf5"), "First_Name" : "Nandan", "Last_Name" : "Kumar", "Age" : "12", "e_mail" : "nandan@gmail.com", "phone" : "8000012345" } { "_id" : ObjectId("6fd6636870fb13eec3963bf6"), "First_Name" : "Chris", "Last_Name" : "Goel", "Age" : "12", "e_mail" : "chris@gmail.com", "phone" : "8000054321" } { "_id" : ObjectId("6fd6636870fb13eec3963bf7"), "First_Name" : "Praveen", "Last_Name" : "Sharma", "Age" : "21", "e_mail" : "praveen@gmail.com", "phone" : "9000011111" }What If the update operation doesn’t match documents in collection? If the update operation doesn't match any documents in the collection, it can automatically insert a new document into the collection which matches the update query by setting the upsert option as true.db.Employees.update( {type:"FullTime"}, {$set:{salary:20000}}, {upsert : true} )WriteResult({"nMatched": 0,  "nUpserted: 1, "nModified":1 })   You can also see the upsert getting reflected in the Write Result of the above operation. upsertoperation in MongoDB is used to save documents into collection . If the document matches query criteria then it will perform an update operation or else it will insert a new document into the collection. Difference between db.collection.update() , db.collection.update One() and db.collection.update Many() The difference is that update() by default, modifies only one document based on the specified filter. However, the user can modify all the documents by adding the modifier {multi: true} . This command works as both updateOne and updateMany command. db.Employees.update (    { "joinYear ": "2020" },    {      $set: { "bonusEligiblity": "False" },    } )Here, it will update only first document which matches the condition.db.Employees.update (    { "joinYear ": "2020" },    {      $set: { "bonusEligiblity": "False" },    }, { multi: true } // Additional Parameter )Here, by adding the parameter – multi: true it works as updateMany() and updates all the documents matching the condition .db.collection.updateOne() --> method to update only one document in a collection.db.Employees.update (    { "joinYear ": "2020" },    {      $set: { "bonusEligiblity": "False" }, // Here multiple parameters can also be updated      } )This update commands use the joinDate =2020 as a filter (match the query) in the collection “Employees”. $set operator (called as update operator) updates the value of the bonusEligiblity to False.You can also update multiple parameters but they need to be separated by a comma (,). E.g.$set: { "bonusEligiblity": "False" , “emp_status : ”New”},db.collection.updateMany() --> method to update multiple document in a collection matching the specified conditiondb.Employees.updateMany(    { "joinYear": "2020" },   { $set: { "bonusEligiblity": "False" },   } )Here, ALL the documents having joinYear =2020 get updated to bonusEligiblity= “False” What If the update operation doesn’t match documents in collection? If the update operation doesn't match any documents in the collection, it can automatically insert a new document into the collection which matches the update query by setting the upsert option as true.db.Employees.update(      {type:"FullTime"},      {$set:{salary:20000}},      {upsert : true}   )WriteResult({"nMatched": 0,  "nUpserted: 1, "nModified":1 })   You can also see the upsert getting reflected in the WriteResult of the above operation. upsert operation in MongoDB is used to save documents into collection . If the document matches query criteria then it will perform an update operation or else it will insert a new document into the collection.Conclusion   To summarize, MongoDB has methods: update() and save() which are used to update documents into a collection. The update() method updates the values in the existing document while the save() method is used to insert a new document or update an existing document if it already contains an _id field The parameters in the document.update() method is a condition for which document needs to be updated, and the next is the update operation which needs to be performed. db.collection.update(query, update, options) In this article, we have gone over the update() method, save () method, updateOne() method and updateMany() method with examples for each. We have also explored the upsert function. Hope this has been useful. The MongoDB course will get you familiar with the popular NoSQL database and arm you with the essential skills to start using Mongo to power your software application. Happy coding! 
Rated 4.0/5 based on 13 customer reviews
7902
How to Update Document in MongoDB

MongoDB provides the update() method to update the... Read More

How to re-engage your employees post COVID-19

Slowly, but surely, we are heading back into the office. The world is reopening and we’re ready to embrace it with open arms. After months of lockdown, you might assume that employees are keen to get back to work. Unfortunately, that is not the case. In this guest post, Natalka Antoniuk) shares about the challenge that Quadrant2Design, an exhibition stand company, are facing with no restart date for their industry yet. She shares insights from their experience with tips to re-engage employees and get your business up and running again.Employee engagement is key to rebuilding a business however, a study by Dr. Nick Keca shows that on average only 29% of employees in your company are actively engaged. They are loyal, committed, more productive and easier to retain which is why they are vital to business regrowth.Employee engagement as per a study by Keka Research  Just over half of your team are likely not engaged, meaning that they can be productive, but they are not psychologically connected to their company.These are the employees who will miss workdays and are more likely to leave.  A fifth of your employees are actively disengaged. These are the employees that you need to work with. These individuals are physically present but are unhappy and psychologically absent. Furthermore, these employees share their unhappiness with others which can influence others who are not engaged. “Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do.” - Steve JobsAs a business owner, employee engagement might not be at the forefront of your mind given the current situation. With businesses starting back up, and huge VAT reductions to encourage economic growth, you are probably more concerned with customer relations and closing deals.  If you don’t actively work towards re-engaging your employees, this might not be possible.After almost five months working from home, employees have realized benefits such as saving time and money by not commuting. They are asking for flexible working patterns, the ability to work remotely, and an openness to new working styles.   This shift in attitudes is going to have a ripple effect when offices do reopen. Although individuals have missed the social aspect of the office, they have made it clear that they want a change. Admittedly restructuring your business amidst a global pandemic isn’t the smartest choice, employers are going to have to do something to keep their staff engaged.  How do you engage employees? Trying to engage your employees, and keep them engaged, was hard before the global pandemic. Now, with the looming recession, job losses, two months of working from home and a virus still in circulation, it is going to be even harder.Nevertheless, the traditional methods that employers have used for years will still be effective and shouldn’t be ignored in your struggle to reengage your team. Reopening your office will take some getting used to after the lockdown. Trying to keep on top of the basic pillars of engagement will go a long way towards keeping your employees happy and motivated. Recognition Employees are more engaged when they feel like their contribution has been recognized. Although remuneration, benefits and rewards are common ways to show your employee that your value their input, you might not be financially stable enough to give these kind of rewards post-COVID. So, what do you do? Fortunately, over 80% of employees value recognition above any rewards or gifts. As long as your employees feel like you appreciate the work they are doing, they will be more actively engaged.  The type of recognition that you give your staff also matters. Over two-thirds of people believe recognition as an individual was more motivating than recognition as a team.Almost 90% of people find praise from their managers to be very or extremely motivation. And three quarters said the same thing about praise from their peers. Recognizing your employees and praising them for their contributions doesn’t cost you any time or money. Look at everything that has been achieved whilst we’ve all had to work from home and get ready to offer individual praise when your doors finally reopen. Growth Employees are more engaged if they feel like there is the potential to grow and develop their career within your organisation. In fact, the majority of people listed opportunities for growth as a more motivating reason to stay at a company than receiving a pay rise.  This is why employee engagement tends to be better in a growing company, as staff members understand the correlation between business growth and new job opportunities. The problem that most businesses will have is that the post-pandemic recession is likely to halt any growth. Whether you are open with your employees or not, there will always be tell-tale signs whether your business is growing or taking a hit. If your staff feel like the business is struggling financially, they will likely disengage quickly. Although growth and career progression might not be on the cards right now, job security is becoming increasingly important as we enter a global recession. Where possible, you need to make every member of staff feel like their job is safe. If you have made any redundancies, then they will likely feel insecure about their position within your organisation. Continue offering praise and recognition for their work so that they feel confident within their role at your company. Fun Without a doubt, the easiest and most effective way to keep your team motivated and engaged is to provide a fun working environment. Nine out of ten employees list fun working environments to be very or extremely motivating.  This doesn’t mean that you need to turn your office into a trendy London agency or Google HQ overnight. Simply building strong relationships and encouraging their out-of-work hobbies can go a long way. Most people are just looking for a healthy work environment. Remember, the vast majority of people have enjoyed the time and money that they have saved by working from home. They have had more time to develop new hobbies and will likely be looking for a better workand life balance.  One of the things you can do to create a more fun working environment is open new avenues of communication. Make your employees feel comfortable coming to you to discuss ideas like flexible working. In building relationships with immediate supervisors and colleagues, your employees will be happier, more motivated and you will notice increased employee engagement.Expect unengaged employees One of the problems business owners are facing is the shift in attitudes that has led to previously engaged employees feeling unmotivated and disengaged. With all of the changes that 2020 has already brought, employees are looking for a sense of normality. Having spent months out of the office only to return to a new socially-distanced environment will take its toll. It is understandable when you look at the three pillars of employee engagement listed above. For months, each team member has been working from home without their colleagues around them. This segregation will have led to a decrease in praise and recognition both from management and on a peer-to-peer level. Furthermore, they are likely to have lost confidence in their job security. With media headlines focussing on the looming recession and the vast number of job losses, many employees are worried about the safety of their own roles.  Finally, any element of fun that was provided in your work environment before has been stripped bare by the 2m social distancing requirements, plastic screens and lingering smell of hand sanitiser. Employees got used to a life working from home where they had more free time available for their family and new hobbies. Now they are back in the office with regulations in place to stop any kind of relationship building.  Of course, the measures we listed above will help you overcome these difficulties. But the truth is that you have a lot of things to consider at the moment. This is a global pandemic and you’re working hard making the right business decisions. Nobody blames you for letting employee engagement slip. But in doing so, you will cause more damage to your business.How do you motivate a disengaged team? It is much harder to motivate an individual who has recently become disengaged. Although we can make assumptions as to why this has happened, you can never be completely sure. That means no employer will ever know a quick fix. The problem is, once an individual becomes disengaged it is hard to get them back on course. A disengaged employee isn’t satisfied with the job that they are doing, they don’t find it exciting and they spend their day clock watching.  Under normal circumstance, when an employee reaches this point, they are likely to be searching for a new job. In the current situation, disengaged employees may feel trapped or threatened by the decreasing job pool. This can lead to further problems down the line as they will vocalise their issues to the other employees, and their negative attitude could start to rub off. Although you don’t want negative people on your team, cutting staff could lead to further disengagement. It is also incredibly cost-effective to actively reengage a current member off staff rather than recruiting new people. So how should you do this? Career development Okay, so you might not be in the best situation to start promoting your employees and dishing out pay raises and bonuses – but you can still let your staff know that their position within your business is safe. Encouraging your staff to attend training programs that enable them to develop new skills will make them feel appreciated. It shows that you intend to have them working for you in the future, giving them a sense of job security.   Be open Share all the company news, good and bad, with your employees. In doing so, you are telling everyone that they are a valuable member of the team. It will help them to engage with the business, company goals, and align themselves with your mission and values. Furthermore, you may find a handful of hidden talents hiding amongst your team. When an employee is disengaged, they pass the day by doing the bare minimum and clock watching. Engaged employees go above and beyond for their company. By being open about the current business situation, your team will become more actively engaged and could even provide solutions to company problems. Lay out your expectations Your business goals will have to be adjusted to help you face the crisis. You may find your product offering, your distribution methods or your marketing strategy have to change. If you are open with your employees, they will already understand that their roles may change slightly moving forward. Make this transition easier by sitting down with each of your employees to discuss their new roles and setting clear expectations, goals and objectives. In doing so, you reiterate the importance of every member of staff and they feel more secure in their job roles with clear targets to work towards. At Quadrant2Design, we are patiently awaiting a reopen date for our industry. Normally at this time of year we are busy designing exhibition stands, however our day-to-day working pattern has changed. Rather than designing stands, we have been creating free resources to help individuals with their exhibition planning and budgeting.  It has been a great exercise for our highly creative team, and something that has seen different groups working together. Overall, we have found this to be extremely helpful in re-engaging our employees. In summary Believe it or not, your employees want to engage at work. Nobody wants to be sat at a desk clock watching for a third of their life. Engaging your team will not only boost your business but make your office a better place to work. The truth of the matter is your employees will find it much easier to stay motivated and engaged at work if you provide the right atmosphere for them to do so. You can do this by following everything that we have outlined above.   Providing an open atmosphere by working on colleague relationships, particularly with supervisors and managers, and keeping the team up to date with the current business situation will be key to this. Furthermore, adjusting to the changing attitudes of staff by encouraging hobbies and becoming more flexible may also benefit engagement. Offer employees the opportunity to grow and develop their career, even if you currently are not in a financial situation to promote and reward them. Letting employees know that their job is safe and there will soon be an opportunity to progress will also be key to maintaining employee engagement.  Finally, take it upon yourself to have a one-to-one with every individual. It could be that their job role has changed as you’ve had to adapt your business offering. Set your expectations and give them personal goals and targets to work towards in this new role. Keeping everyone on board will be crucial in business regrowth post-COVID19.
Rated 4.0/5 based on 13 customer reviews
7036
How to re-engage your employees post COVID-19

Slowly, but surely, we are heading back into the o... Read More

Key Insights from the 2020 State of Agile Report

How are agile businesses changing in 2020?  Digital.ai, the creator of the industry’s first intelligent Value Stream, recently published its 14th Annual State of Agile Report, along with a survey addendum to reflect the current 2020 landscape. The report took a look into the enterprise, what Agile techniques companies are implementing, their benefits, and what’s trending. The report provides the most comprehensive data in the world to benchmark your Agile practice and plan your next wave of expansion. The survey documents the experiences of more than 1,100 business and IT professionals across a range of industries and roles worldwide.  About 40,000 Agile practitioners, consultants, and executives have shared their insights to make this the longest-running and largest report of its kind. For the first time, it revealed insights beyond the general results by filtering the results along the demographic lines. The analysis indicates a correlation between the time practicing Agile, the ability to manage the changing priorities, and improved time to market.  In this article, we give you the complete lowdown on the state of Agile in 2020 including the COVID-19 impact and what’s next in Agile. Agile in numbers Let us explore the top responsesto the survey in numbers. Respondents answered their top reasons for implementing Agile techniques, which techniquesand methodologies they employ the most, what tools they recommend most, and the top benefits of using Agile. Top five reasons for adopting AgileTop five benefits of adopting agileRespondents were asked why their teams adopted Agile methodologies and techniques. These were the most responded benefits: Accelerate software delivery (71 percent) Enhance the ability to manage changing priorities (63 percent) Increased productivity (51 percent) Improve business/IT alignment (47 percent) Enhance software quality (42 percent)  This year, the reasons for implementing Agile were more about reducing project risks as opposed to reducing project costs.Top five Agile techniques employedThese are the five most used tactics that help teams adhere to the twelve principles of Agile.Top five Agile techniques employedThe Daily Standup was the most common Agile technique used in organizations. The most notable changes from last year was a decrease in Release Planning (51 percent this year as opposed to 57 percent last year) and an increase in Product Road Mapping (49 percent this year as opposed to 45 percent last year). Top five benefits of adopting AgileTop five benefits of adopting AgileWe see that the top five benefits of adopting Agile are built around speed and adaptability. Project Cost Reduction was last on the list with only 26 percent of the respondents considering it to be the benefit of Agile implementation. Top five Agile methodologies Top five Agile methodologiesThe survey shows that Scrum and its variants are the most common methodologies used for Agile implementation. 3 percent of the respondents didn’t have any idea of the methodology used by their organization.  Top five Agile project management toolsTop recommended project management toolsRespondents were asked if they would recommend the tools on the basis of their experience. Atlassian JIRA and VersionOne were the most recommended tools. Five critical takeaways from the 2020 State of Agile Report Many organizations still learning to adopt AgilePercentage of teams using AgileThe survey showed that only 18 percent of the organizations implemented Agile for all the teams. 77 percent of the organizations had still not implemented Agile in all the company’s teams. With 5 percent of the organizations yet to adopt Agile, there is clearly plenty of area for growth. Agile maturityWhile 95 percent of organizations have some form of agile process in place, practice maturity and adoption remain a work in progress. Around 50 percent of respondents report that less than half of their teams are using agile, and 84 percent acknowledge that their organizations are below a high level of competencies.  Areas other than software development yet to take advantage of AgileAreas of organization practicing AgileAgile practices are not limited to software organizations. The survey data showed that while Software Development continues to be the major area for Agile adoption, other areas like IT and Operations have also started adopting the methodology. Other areas in the organization are yet to take advantage of everything the Agile approach has to offer. More business outcome KPIs, fewer metrics As per the respondents, accelerated delivery speed is the most critical measure of the success of Agile initiatives. Next is improved quality, followed by reduced risk and increased customer satisfaction. Reduced IT costs is low on the spectrum with just 39 percent considering it as important for measuring success.  How success is measured in Agile transformationsAgile success and metricsWhen asked how organizations measure success of Agile transformations, the top measures of success were consistent with those reported over the last few years. Outcomes, customer satisfaction and business value, ranked higher than outputs like on-time delivery and productivity. The survey results for this section remain consistent over the past few years. There might be some ups and downs. But overall, Customer Satisfaction and Business Value are at a higher rank than productivity and on-time delivery. How success is measured in individual Agile projectsAgile success and metricsAs with Agile transformations, business value delivered, and customer or user satisfaction remained the top two cited measures of success within for individual projects.  Scaling Agile faces culture challengesMethods and approaches of scaling AgileAbout one-third of respondents are applying the Scaled Agile Framework, roughly another third are using other scaling frameworks, and another third stated they didn't know/other. There appear to be several common challenges scaling agile as over 40 percent of respondents cited six different challenges/barriers with adopting and scaling agile practices. These included: resistance to change, lack of leadership participation, inconsistent processes, misaligned organization versus agile values, inadequate management support, and insufficient training.    Challenges experienced when adopting and scaling AgileEnterprises are adopting the framework at a remarkable rate that shows that companies want to get the benefits of a structured framework included in the Lean/Agile BoK of SAFe.  The lack of qualified professionals also remains one of the common challenges with insufficient leadership participation (46 percent) at number 2 and lack of experience or skills with Agile methods (41 percent) at number 6.  The report also shows that culture is at the primary target of change as it affects the thinking and working of the organization. Agile organizations slowly adopting DevOps DevOps practices are a strong partner to agile methodologies, and 69 percent of survey respondents stated that DevOps transformation was either important or very important to their organization. But adoption of DevOps practices lags its important with only 55 percent employing continuous integrations and 41 percent continuous delivery. Only 36 percent practice continuous deployment. The top two benefits targeted are accelerated delivery speed (70 percent) and improved quality (62 percent). But respondents are tackling quality first with 67 percent implementing unit testing and 58 percent coding standards, even higher engineering practices over the 55 percent on continuous integration.  More than half of the respondents reported that their organization was already implementing Value Stream Management (VSM) or have plans to do so. VSM is a combination of people, technology, and processes that maps, measures, optimized, visualized, and governs the business value flow using a heterogeneous enterprise delivery pipeline.  Each level of automation requires investment and additional work to prove its robustness. There are seven prerequisites before improving release frequencies, and that requires investment in aspects of these seven DevOps practices. Even so, there are questions DevOps teams should answer before increasing deployment frequency. Summary of key insights Currently, the Agile approach is predominantly implemented in the software or information technology sector. The benefits an organization can reap once Agile is implemented in other areas as well would be tremendous. Here is a quick summary of key insights from the report: Cost reduction is not anymore one of the primary reasons to adopt the Agile approach. Identifying technical risk before deployment is considered very valuable by 34 percent of the respondents, which was 22 percent last year. Greater Agile maturity is correlated to the time of practicing Agile. The length of time since Agile adoption is also related to the increased ability to manage the changing priorities and improved time market. Organizations that have practiced Agile for more than 5 years have a greater percentage of DevOps initiatives and interest in Value Stream Management.  Companies with 20,000 or more people are more likely to have been using Agile for 5 or more years. Companies with less than 1,000 people correlated to a higher percentage of all their teams implementing the Agile approach.  More than half of the respondents stated their companies are either implementing VSM or have plans to do so.  Risk and compliance increased by 54 percent to be the top value to identify and measure technical risk before the deployment begins. SAFe is the most popular scaling method, increasing 5 percent over the last year. There was a shift in Agile techniques as release planning decreased by 11 percent while product road-mapping increased by 9 percent. This change can be attributed to the increase in CI/CD and better program increment planning. Currently, Agile is mainly confined to software development, operations, and the IT sector. However, it is expected that by next year, the organization will expand agility into areas beyond developing, deploying, and maintaining software solutions. The COVID-19 impact and what’s next in Agile The COVID-19 pandemic has triggered a health emergency worldwide. Leaders across industries are moving promptly to protect employees and build resilience, as the impact of the crisis continues to mount. In mid-May 2020, Digital.ai conducted a brief supplemental survey of respondents to learn more about how the COVID-19 pandemic has affected their Agile adoption. Supplemental findings reveal that: 55 percent say their company plans to increase the use of Agile in the next 12-14 months. This is an increase of 13 percent over the original survey completed just five months ago. 43 percent of organizations say their momentum for Agile adoption has increased over the past 90 days, with 15 percent saying it has increased significantly. 33 percent say they increased or expanded Agile adoption in the last 90 days to help manage distributed teams. In summary, forecasters continue to predict how long the COVID-19 crisis will last, but it seems inevitable that many organizations will be working remotely for the foreseeable future.Implemented correctly, an agile approach can help remote teams function effectively and build resilience for the future.  Following the pandemic, working from home more frequently (perhaps 2-3 days per week) may become an accepted norm for many companies, as this could realize cost efficiencies and prove that an agile, remote working model is productive.
Rated 4.0/5 based on 16 customer reviews
7057
Key Insights from the 2020 State of Agile Report

How are agile businesses changing in 2020?  Digit... Read More

A Guide to Using AI Responsibly

"The artificial intelligence (AI) that we develop is impacting people directly or indirectly. And often, they don’t deserve the consequences of those impacts, nor have they asked for it. It is incumbent upon us to make sure that we are doing the right thing”.- Dr. Anthony Franklin, Senior Data Scientist and AI Engineer, MicrosoftDigitally addressing a live global audience in a recent webinar on the topic of ‘Responsible AI’, Dr. Anthony Franklin, a senior data science expert and AI evangelist from Microsoft, spoke about the challenges that society faces from the ever-evolving AI and how the inherent biased nature of humans is reflected in technology.Drawing from his experience in machine learning, risk analytics, analytics model management in government as well as data warehouse, Dr. Franklin shed light on the critical need to incorporate ethics in developing AI. Citing examples from various incidents that have taken place around the world, Dr. Franklin emphasized why it is critical for us to have an uncompromising approach towards using AI responsibly. He talked about the human (over)indulgence in technology, the challenges that society faces from the ever-evolving AI and how the inherent biased nature of humans is reflected through technology.The purpose of the talk and this article is to help frame the debate on responsible AI with a set of principles we can anchor on, and a set of actions we can all take to advance the promise of AI in ways that don’t cause harm to people. In this article, we present key insights from the webinar along with the video for you to follow along.KnowledgeHut webinar on Responsible AI by Dr. Anthony Franklin, MicrosoftWhat is the debate about?These are times when we can expect to see policemen on the streets wearing AI glasses, viewing, and profiling the public. Military organizations today, can keep an eye on the public. Besides, a simple exercise of googling the word CEO, would result in pages and pages showing white men.Police using AI glasses for public surveillance in ChinaThese are just some of the examples of the unparalleled success we have achieved in technology coupled with the fact that the same technology has overlooked the basic ethics, moral and social.Responsible AI is a critical global needIn a recent study conducted from among the top ten technologically advanced nations, nearly nine of ten organizations across countries have encountered ethical issues resulting from the use of AI.Source: Capgemini    Artificial intelligence has captured our imagination and made many things we would have thought impossible only a few years ago seem commonplace today. But AI has also raised some challenging issues for society writ large. We are in a race to advance AI capabilities and everything is about collecting data. But, what is being done with the data?Advancements in AI are different from other technologies because of the pace of innovation and its proximity to human intelligence – impacting us at a personal and societal level.While there remains no end to this ever-ending road of development, the need for us to ensure an equally powerful framework has increased even more. The need for a responsible AI is a critical global need.What developers are saying about ethics in AIStack Overflow carried out a couple of anonymous developer focused surveys in 2018. Some of the responses are a clear indication of how the machine is often so powerful. While we wish the answers were all "No", the actual answers are not too surprising.1. What would the developers do if asked to write a code for an unethical purpose?The majority (58.5 percent) stated they would clearly decline if they were to be approached to write code for an unethical purpose. Over a third (37 percent), however, said they would do if it met some specific criteria of theirs.2. Who is ultimately responsible for the code which accomplishes something unethical?When asked with whom the ultimate responsibility lies if their code were to be used to accomplish something unethical, nearly one fifth of the developers acknowledge that such a responsibility should lie with the developer who wrote the code. 23 percent of the developers stated that this accountability should lie with the person who came up with the idea. The majority (60 percent), however, felt that the senior management should be responsible for this.3. Do the developers have an obligation to consider the ethical implications?A significant majority (80 percent) acknowledged that developers have the obligation to consider ethical implications. Though in smaller numbers, the above studies show the ability of the developers to get involved in unethical activity and the tendency to brush off accountability. Thus, there is a great and growing need not just for developers, but also for the rest of us to work collectively to change these numbers.The six basic principles of AIThough ambiguous, the principles attached with the ethics of AI remain very much tangible. Following are the six basic principles of AI:1. FairnessFairness (noun)the state, condition, or quality of being fair, or free from bias or injustice; evenhandednessDiscriminationOne of the many services which Amazon provides today includes the same-day-shipping policy. The map below shows the reach of the policy in the top 6 metropolitans in the US.Source: Bloomberg   In the city of Boston, one can see the gaps, the places where the service is not provided. Coincidentally, these areas turned out to be areas inhabited by individuals belonging to the lower economic strata. In defence, the Amazon stated that the policy was meant primarily for regions with denser Amazon users. Whichever way this is seen, the approach still ends up being discriminatory.We see examples of bias in search as well. When we search for “CEO” in Bing, we see that all pictures are pictures of mostly white men, creating the impression that there are no women CEOs.RacismWe see examples of bias across different applications of AI. An image of an Asian American was submitted for the purpose of renewing the passport. After analysing the subject, the application’s statement read “Subjects eyes are closed”.This highlights the unintentional, but negatively impactful working of a data organization. It further goes on to show how an inherent bias held by humans, transcends into the technology we make.An algorithm widely used in US hospitals to allocate healthcare to patients has been systematically discriminating against black people, a sweeping analysis has found.The study, published in Science in October 2019, concluded that the algorithm was less likely to refer black people than white people who were equally sick, to programmes that aim to improve care for patients with complex medical needs. Hospitals and insurers use the algorithm and others like it to help manage care for about 200 million people in the United States each year.As a result, millions of black people have not been able to get equal medical treatment. To make things worse, data suggests that in some way or the other, the algorithms have been set up to make money.In 2015, Google became one of the first to release a facial recognition programme. The system recognized the Caucasians perfectly well, but the same system identified a black person with an ape.These examples of bias in technologies are not isolated from the society we live in. The society we live in has different forms of biases that may not consistent with a corporation’s values, but these biases may already be prevalent in their data sets.With the widespread use of AI and statistical learning, such enterprises are at serious risk not only of spreading but also amplifying these biases in ways that they do not understand.These examples demonstrate gross unfairness on multiple fronts, making it necessary for organizations to have a more diverse data in general.2. Reliability and SafetyReliability (noun)the ability to be relied on or depended on, as for accuracy, honesty, or achievement.Safety (noun)the state of being safe; freedom from the occurrence or risk of injury, danger, or loss. the quality of averting or not causing injury, danger, or loss.In the case of an autonomous vehicle, when can we as a consumer be 100% sure of our safety? Or can we ever be? How many miles does a car have to cover or how many people are to lose their lives before the assurance of the rest?In the case of autonomous vehicles, how can we as consumers be 100 percent sure of our safety? Or can we ever be? How many miles does a car have to cover or how many people are to lose their lives before the assurance of the rest? These are just a few of the questions a company must answer before establishing themselves as a reliable organization.A project from scientists in the UK and India shows one possible use for automated surveillance technology to identify violent behavior in crowds with the help of camera-equipped drones.In a paper titled “Eye in the Sky,” the researchers used uses a simple Parrot AR quadcopter (which costs around $200) to transmit video footage over a mobile internet connection for real-time analysis. A figure from the paper showing how the software analyzes individuals poses and matches them to “violent” postures. The question is: how will this technology be used, and who will use it?Researchers working in this field often note there is a huge difference between staged tests and real-world use-cases. Though this system is yet to prove itself, it is a clear illustration of the direction contemporary research is going.Using AI to identify body poses is a common problem, with big tech companies like Facebook publishing significant research on the topic. Many experts agree that automated surveillance technologies are ripe for abuse by law enforcement and authoritarian governments.3. Privacy and securityPrivacy (noun)the state of being apart from other people or concealed from their view; solitude; seclusion:the state of being free from unwanted or undue intrusion or disturbance in one's private life or affairs; freedom to be let alone:Security (noun)freedom from danger, risk, etc.; safety.freedom from care, anxiety, or doubt; well-founded confidence.something that secures or makes safe; protection; defense.Strava’s heat map revealed military bases around the world and exposed soldiers to real danger – this is not AI per se, but useful for a data discussion. A similar instance took place in Russia, too.The iRobot’s latest Roomba’s i7+ Robovac maps users’ homes to let them customize the cleaning schedule. An integration with Google Assistant lets customers give verbal commands like, “OK Google, tell Roomba to clean the kitchen.” - this is voluntary action and needs user’s consent.Roomba’s i7+ Robovac maps users’ homes to let them customize the cleaning scheduleIn October 2018, the company admitted it had exposed the personal data of around 500,000 Google+ users, leading to the closure of the platform. It also announced it was reviewing access to Gmail by third-party companies after it was revealed that many developers were reading and analyzing users’ personal mail for marketing and data mining.A 2012 New York Times article, spoke about a father who found himself in the uncomfortable position of having to apologize to a Target employee. Earlier, he had stormed into a store near Minneapolis and complained to the manager that his daughter was receiving coupons for cribs and baby clothes in the mail. It turned out that Target knew his teen daughter better than he did. She was pregnant and Target knew this before her dad did.By crawling the teen’s data, statisticians at Target were able to identify about 25 products that, when analysed together, allowed them to assign each shopper a “pregnancy prediction” score. More importantly, they could also estimate her due date to within a small window, so they could send coupons timed to very specific stages of her pregnancy.There was another instance reported in Canada of a mall using facial recognition software in their directories June to track shoppers' ages and genders without telling them.4. InclusivenessInclusiveness (adjective)including or encompassing the stated limit or extremes in consideration or account (usually used postpositively)including a great deal, or encompassing everything concerned; comprehensiveIn the K.W vs Armstrong case, the plaintiffs were vulnerable adults living in Idaho, facing various psychological and developmental disabilities. They complained to the court when the Idaho Department of Health and Welfare reduced their medical assistance budget by a whopping 42%.The Idaho Department of Health and Welfare claimed that the reasons for the cuts were “trade secrets” and refused to disclose the algorithm it used to calculate the reductions.K.W. v. Armstrong plaintiff, Christie MathwigOnce a system is found to be discriminatory or otherwise inaccurate, there is an additional challenge in redesigning the system. Ideally, government agencies should develop an inclusive redesign process that allows communities affected by algorithmic decision systems to meaningfully participate. But this approach is frequently met with resistance.5. TransparencyTransparency (adjective)having the property of transmitting rays of light through its substance so that bodies situated beyond or behind can be distinctly seen.admitting the passage of light through interstices.so sheer as to permit light to pass through; diaphanous.easily seen through, recognized, or detectedA company in New Orleans assisted the police officials to predict the individuals and their likelihood of committing crimes. This is the example of the usage of predictive analytics for policing strategies, carried out secretively.In the Rich Caruana case study, 10 million patients data, and 1000’s of features were used to train a model on the data to predict the risk of pneumonia and decide whether patients must be sent to hospital. But was this model safe to deploy and use on real patients? Was the test data sufficient to make accurate predictions?Unfortunately, a bunch of different machine learning models had been used to train an accurate black box, without knowing what was inside. Multitask neural net was thought to be the most accurate, but was the approach safe?The pattern in the data, strictly speaking, was accurate. The good news was that the treatment was so effective that it lowered the risk of dying compared to the general population. However, the bad news was that if we used this model to make decisions about whether to admit the patient to the hospital, it would be dangerous to asthmatics and hence, not at all safe to use.Not only is this an issue of safety, but also a case of violation of transparency. The key problem is that there are bad patterns we don’t know about. While neural net is more accurate and can learn things fast, one doesn’t know everything that the neural net is using. We really need to understand the model before we deploy it.Now, through a technique called Generalized Additive Models, whereby the influence of individual attributes in the training data can be independently measured, a new model has been trained where the outputs are completely transparent, but actually improved performance over the old model.Asthmatics were now being sent home sooner because they were rushed to the front of the line as soon as they arrived at the hospital. Faster and more targeted care led to better results. And all the model learned from were the results.In another instance, one of the tools used by the New Orleans Police Department to identify members of gangs like 3NG and the 39ers came from the Silicon Valley company Palantir. The company provided software to a secretive NOPD program that traced people’s ties to other gang members, outlined criminal histories, analyzed social media, and predicted the likelihood that individuals would commit violence or become a victim.As part of the discovery process in the trial, the government turned over more than 60,000 pages of documents detailing evidence gathered against him from confidential informants, ballistics, and other sources — but they made no mention of the NOPD’s partnership with Palantir.6. AccountabilityAccountability (adjective)subject to the obligation to report, explain, or justify something; responsible; answerable. capable of being explained; explicable; explainable.Like in the example of autonomous vehicles, in case of any mishap, where does the accountability lie? Who is to be blamed for the loss of lives or any sort of destruction in a driverless car?With driverless cars, the question remains: Who is to blame?It appears that the more advanced the technology, the faster it is losing its accountability. Be it a driverless car crashing or a robot killing a person, the question remains: who is to blame.Whom does one sue if I were to get hit by a driverless car? What if a medical robot gives a patient the wrong drug? What if a vacuum robot sucks up one's hair while they are napping on the floor? And can a robot commit a war crime? Who gets to decide whether a person deserves certain treatment in an algorithm-based health care policy? Is it the organization which developed it or the developer who made it? There is a clear case of lack of accountability in such situations.Liability of automated systems, the debate continues.The key word in the above-mentioned principles is impact. The consequence of any AI programming, intentional or unintentional, leaves a strong impact.The responsible AI lifecycleBoth the Association for Computing Machinery (ACM) and the Institute of Electrical and Electronics Engineers (IEEE) published ethics guidelines for computer scientists in the early 1990s. More recently, we have seen countless social scientists and STS researchers sounding the alarm about technology’s potential to harm people and society.To turn talk about responsible AI into action, organisations need to make sure that their use of AI fulfils several criteria. After defining the basic AI principles, an organization can develop a prototype. But they must be open to change even after launching what they assume to be the most fool-proof AI service.Microsoft’s Responsible AI Lifecycle is built on six key principles, namely:Define: Define the objectives, data requirements and responsible metrics.Envision: Consider the consequences and potential risks by continually analysing and improving.Prototype: Build prototypes based on data, models and experience, and test frequently.Build: Build and integrate AI according to responsible metrics and trade-offs.Launch: Launch only after diverse ring-testing with escalation and recovery planEvolve: By continuously analysing and improving.Responsible AI Lifecycle. Source: MicrosoftMicrosoft is leading the way with detailed guidelines to help teams put responsible AI into practice. Their Guidelines for Human-AI Interaction recommend best practices for how AI systems should behave upon initial interaction, during regular interaction, when they’re inevitably wrong, and over time. They are to be used throughout the design process as existing ideas are evaluated, new ideas are being brainstormed, and collaboration undertaken across multiple disciplines in creating AI.In addition, there are several types of guidelines given to engineering teams including conversational AI guidelines, inclusive design guidelines, an AI fairness checklist, and an AI security engineering guidance.All guidelines are designed to help teams anticipate and address potential issues throughout the software development lifecycle to mitigate security, risks, and ethics issues.Principles to practicesAI is already having an enormous and positive impact on healthcare, the environment, and a host of other societal needs. These rapid advances have given rise to an industry debate about how the world should (or shouldn’t) use these new capabilities. As these systems become increasingly important to our lives, it is critical that when they fail that we understand how and why, whether it is inherent design of a system or the result of an adversary. In conclusion, Dr. Franklin emphasized the need for enterprises to understand how bias can be introduced and affect recommendations. Attracting a diverse pool of AI talent across the organization is critical to develop analytical techniques to detect and eliminate bias, he stressed.We hope Dr. Franklin's webinar and this article have helped frame the debate on responsible AI and provided us with a set of principles we can anchor on, and a set of actions we can take to advance the promise of AI in ways that don’t cause harm to people.
Rated 4.5/5 based on 1 customer reviews
4604
A Guide to Using AI Responsibly

"The artificial intelligence (AI) that we develop ... Read More