Fixed | Error api-ms-win-crt-runtime-l1-1-0.dll is missing from your computer

Today while I was working with one of the Windows programs, it crashed with the following error
The program can't start because api-ms-win-crt-runtime-l1-1-0.dll is missing from your computer.
Try reinstalling the program to fix this problem.

The missing dll “api-ms-win-crt-runtime-l1-1-0.dll” as the name suggests is part of Visual C++ run time. Instead of reinstalling the program as the error suggested, I decided to find out why this DLL was missing. When I looked up in Control Panel, I did not find “Microsoft Visual Studio **** runtime” program installed.

Since I know the reason for the error, the fix is simple. Just downloaded and installed Visual C++ Redistributable for Visual Studio 2015.

Extracting numbers from strings in Python

Numbers are everywhere. While I was getting hands-on with MongoDB, I was working with various documents. I thought of writing this small post while I was extracting numbers from a document.

I use Python extensively for text processing. Text manipulation is very easy with Regular Expressions (RegEx). The following example in which I get the job done with just one line of RegEx explains why it is the best.

Here findall(‘\d+’) does the magic. What does “\d” do? As explained here, it matches any decimal digit (0-9).

If that is the case why that extra “+” after \d?
“\d” matches ONE decimal digit where as “\d+” matches the subsequent decimal digits after the first match. This can be better explained if I run the following code with and without “+” after “\d”.

Output with “\d”

['1', '1', '1', '0', '1', '1', '1', '5', '2', '5']

Output with “\d+”
['1', '1', '10', '11', '15', '25']

As evident from these output, “\d+” gives us the right results by getting the complete number instead of the individual digits separately.

How to drop database in MongoDB?

With the help of couple of commands a database can be dropped in MongoDB. There is a slight difference in the way we drop database when compared to traditional RDBMS.

In traditional RDBMS, in order to drop the database it should not be in use. For example, in order to drop the database “A” I need to be executing the command under the context of some other database, as seen below.

If we don’t follow this, the command will fail with an error that the database is already in use.

But in MongoDB, its the other way around. In order to drop the database, the command must be executed under the same database’s context. The method to be used is db.dropDatabase()

Please note that the methods in MongoDB are case sensitive.

What will happen if you execute db.dropDatabase() without being under the context of the intended database? In this case if the default test database exists, it will be dropped. If the test database does not exist, the command will still execute successfully but no database will actually be dropped.

It is important to note that if there are any users are created in the database being dropped, those users will NOT be deleted. Those users need to be dropped by executing dropAllUsersFromDatabase under the context of that database. We will discuss about users in the upcoming posts.

Stay tuned!

How to create a database in MongoDB

This is a very basic post on how to create a database in MongoDB. But if you are like me who has worked with traditional RDBMS for a long time, you would start looking for the CREATE DATABASE command’s alternative in MongoDB.

There is no CREATE DATABASE in MongoDB! So how do we create a new database? Just issue a USE databasename command. Something like this.

Now it’s time to see if the database is created successfully or not. show dbs is the command to check this.

Suprise! We don’t see MyTestDB in this output! The database is created but it would not show up until we insert a document into it. Use the following command to insert a document named testsuccessful into the database.

After inserting a document issue show dbs command again and you would notice that the database is now listed.

With this we have now successfully created a new database in MongoDB.

Working with directories in R

When you are working with R you will need to import/export files. It is important to know how to navigate directories in R. In this post I will touch upon few basic commands/options in R which help us to work with directories.

getwd()

As the name suggests getwd gets us the current working directory. This is a useful command when we want to confirm the current working directory. Here is a sample output.

setwd()

This is an essential function when working with files in R. Let us assume, I want to import a file named TestData.csv which is located in C:\Pradeep folder. In case we are in a wrong folder, R will return the following error.

Using getwd() I understood that I wasn’t in the desired folder. Now to change the current working directory, I can make use of setwd() function. Here is the command.

I am using R on Windows. Please note that I am not using the  \ (back slash) after C: Instead I am using / (slash). This is because in R back slash is an escape character. If I ignore this and use C:\Pradeep, it would result in the following error.

I use R Studio to work with R. When I am working on a Project in R Studio, by default the current working will be set to the folder where that project’s files are located. At times when I am testing out features or working on something trivial, I tend to keep all such files in a same folder. These are just files and not associated with any project in R Studio. To help in such cases, R Studio has a nice little option. Under Tools –> Options,  we can specify the Default working directory (when not in project) as seen in the following screenshot.

With this setting, we need not worry where to look for those files which were not part of any project.

How to install MongoDB as a Windows Service?

For any important service it is important to be always accessible. After a server maintenance no one wants to be paged that the database services were stopped. Hence it is important to have that service to be installed as an OS service so that manual intervention is not needed after a server reboot.

In my previous post we learnt how to install and start MongoDB manually. In this post we will learn about installing MongoDB as a Windows service.

First open a Command prompt window as an administrator. This is important because installing a service requires elevated privileges on Windows.

Second step is to ensure that the Data folder is created. In the absence of these default folders, we will encounter errors and MongoDB fails to start. The folders can be placed anywhere because we will configure MongoDB to point to them in the subsequent step.

When starting MongoDB manually we can specify the dbpath and other related things as variables. However when it is starting as a Windows service, it is important to have a configuration file so that MongoDB knows where to look for the database files and where to write the logs. You can create this file anywhere and name it anything. In this example I will place it in a different folder than the data directory i.e. C:\Program Files\MongoDB\Server\3.4\bin\mongodb.config

Now in the last step of installation, I call the mongod.exe with –install and –config parameters. As the name suggests –install parameter installs MongoDB as a Windows service and –config parameter points the service to the correct configuration file to pick the values from.

Now if we open the services console, MongoDB service will be listed and it will be set to start Automatically.

MongoDB fails to start with exception in initAndListen: 29 error

Yesterday I talked about how to install MongoDB on Windows. In this post I will talk about the most common error that one encounters when starting MongoDB for the first time.

Like I mentioned in the previous post, to start MongoDB from the command prompt, we need to type mongod. Most users encounter the following error on starting MongoDB for the first time.

Here is the error of interest.
2017-01-11T10:48:29.135+0530 I STORAGE [initandlisten] exception in initAndListen: 29 Data directory C:\data\db\ not found., terminating

By default MongoDB creates the databases in C:\Data\DB on Windows (/data/db on Linux). We are getting this error because the folder does not exist. The easiest way to resolve this error is to created the folder C:\Data\DB.

What if I don’t want MongoDB to create databases on C drive? The –dbpath parameter comes to the rescue here. Here is a sample command where I am pointing the databases to be created on Z:\data directory.

            mongod --dbpath z:\data

We can also make use of a configuration file to set this parameter. We will discuss about the configuration parameter in the subsequent posts.

Getting started with MongoDB on Windows

MongoDB is an open-source, document oriented database. Document oriented database does not mean that this database is used for storing documents like .txt, .jpg files instead it means that the data is stored in the database in JSON (JavaScript Object Notation) format.

In this post I will briefly take you through the steps to i nstall and use MongoDB on your workstation. More detailed instructions on installing it as a service, configure MongoDB clusters will be covered in the subsequent posts.

First of all download the MongoDB installer from the Download Center. In this post, I have downloaded the 3.4.1 of MongoDB installer for Windows. Launching the Installer will take you to the following screen, click Next and accept the agreement.

Chose “Complete” in the following screen.

Within a couple of minutes, the installation will succeed.

Now the installation is done but where did it install MongoDB? By default, it is installed in C:\Program Files\MongoDB\Server\3.4\bin folder.

To avoid changing to this directory every time we want to use MongoDB, we can add this folder to the PATH environment variable as shown in the following screenshots.

After this whenever we open a command prompt, we can call any MongoDB binary without switching to the default installation folder.

Now we are good to launch MongoDB. But there is one important step that we need to take care before starting MongoDB. While starting MongoDB, it looks for the default data directories and creates the databases in that folder. On Windows the default data directory is c:\data\db. In case this folder structure does not exist, we need to create it manually either in command prompt or in Windows Explorer.

Once this is done we are good to launch MongoDB. To do this open a command prompt window and type mongod. Within a few seconds, MongoDB process is launched and it starts waiting for connections on the default port 27017.

Once the process is launched we can connect to it and work normally on a different command prompt window (since the process is running in the current window). There are some very good GUI based MongoDB clients, MONGO is a simple command line MongoDB shell.

Just typing MONGO in a command prompt window will connect to the local instance of MongoDB as seen in the following screenshot.

Hope you liked my first post on MongoDB. In the subsequent posts, I will cover various aspects of administering and development in MongoDB.

An unresolvable problem occured while initializing the package information

Today while updating the packages on Ubuntu server, I got the following error message.
COULD NOT INTITIALIZE THE PACKAGE INFORMATION
An unresolvable problem occured while initializing the package information
Please report t:his bug against the 'update-manager' package and include the
following error message:
'E: Malformed line 91 in source list/etc/apt/sources.list
E: The list of sources could not be read.,
E: The package list of status file could not be parsed or opened.

The following line is of interest in the error message.

Malformed line 91 in source list/etc/apt/sources.list

Since it is self-explanatory, all I had to do was to check Line 91 in sources.list file.
For editing files quickly Nano editor is my favorite.

It turned out that line 91 had a misspelt URL and all I had to do was to fix that.

After this the package information had to be updated from the repositories by executing apt-get.

Now this command executed without any problems and the package information was updated.

Using APT-GET in Ubuntu

Ubuntu maintains a database of available packages. This database needs to be updated from time to time to ensure that the OS is aware of new packages availability. apt-get is the command to update this database.

To update the package database the following command needs to be run with super user privileges.

As seen in the following screenshot, running this command contacts various servers to get the latest package information.

For each line you would see a status (highlighted in yellow). In short here is what they mean.

  • Ign: The package is ignored. APT can ignore a package due to various reasons.
  • Hit: The package version on the remote server and local are the same.
  • Get: A new version of the package is available. Information about the new package will be downloaded but not the actual package.

Since the Package database is now updated using apt-get update, we can upgrade the actual packages using the following command.

Depending upon how many packages are to be upgraded, you will see a screen similar to this.

More details about APT-GET can be found at Ubuntu Documentation.