Posts

Showing posts with the label MongoDB

Creating a Schema in MongoDB

Image
What is a Schema ? Schema does not need to have the same set of fields or structure, and common fields in a collection’s documents. If you are familiar with sql queries, you might know that we define the variables  and data types in a predefined structure when creating tables.But when using schema you can consider the following points. Design your schema according to user requirements. Combine objects into one document if you will use them together. Otherwise separate them (but make sure there should not be need of joins). Duplicate the data (but limited) because disk space is cheap as compare to compute time. Do joins while write, not on read. Optimize your schema for most frequent use cases. Do complex aggregation in the schema. Lets try out how to create a schema to get a better idea. First create a directory in your project folder to store these separately. Now create file to create the schema.Here we should require Mongoose. Go through the  article ...

MongoDB Connections in MEAN Stack

Image
This article will  help you to get to know how to build up a database connection using mongodb. For this I am using  Mongoose  which is done by using object modelling. First install mongoose using your command line and save it in the package.json file. npm install mongoose --save Now you can see that the dependency has been created in package.json file.Now require this into app.js file.Now you can create the database connection.Here before creating the connection, you should have run the mongo server. For that move on to the location where you have installed mongodb. If you haven't installed MongoDB refer  this article Now move on to the bin folder and run the mongod server by typing mongod. as the output you can get the following. Here port 27017 means the default port for mongo. Creating the Connection To create the connection create a new folder in your project called config in order to  reduce the complexity of ...

Installing MongoDB into Windows

Image
This article will help you to get to know the way of installing MongoDB in to Windows. Lets get started. Step 01 : Download  MongoDB  from the website Step 02: Install it by following the steps in the setup. Step 03 : Move on to the bin folder in  MongoDB folder Go through  C:\Program Files\MongoDB\Server\3.6\bin to get the bin file. This path may change with the version that you are using.The window will looks like below. Step 04: Install mongo and mongod applications init. Open the command line in the bin folder to install mongod There it shows  an error that a database is not found.Here you need to create folder called data in c:/ and inside it another folder called db to store any information stored in Mongo. Now again try the mongod command and see. You will get an output like this which means that mongo is waiting for connections. To install mongo as same we did above type mongo in the command line.Then type db and...