Skip to main content

Posts

Showing posts with the label How to create database in MongoDB?

MongoDB CRUD Operation in ASP MVC.Net

Table of Content :- 1.       MongoDB Setup and Installations 2.       Add a User Registration Page and Save Records in MongoDB 3.       Get User Records from MongoDB through LINQ 4.       Edit/Update Records in MongoDB 5.       Delete/Drop Records from MongoDB through LINQ MongoDB Setup and Installations :- 1.       Download MongoDB using below link, http://www.mongodb.org/downloads?_ga=1.20290616.1294468948.1419862328 2.       Setup MongoDB as per below link instructions, http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/ Stayed Informed – YouTube Video link for Setup MongoDB Stayed Informed - Why use MongoDB in MVC .Net? The main Reason is to Use MongoDB with ASP.Net MVC are, 1.       So Faster Development. 2.    ...

3 Best Ways to Rename MongoDB Database [Rename]

“ How do you rename a MongoDB database ”?  “ How to Backup and Restore MongoDB using mongodump and mongorestore ”? “ 3 Ways ” to Rename MongoDB Database as, 1.       Rename with Database copy. 2.       Rename with Backup/Restore. 3.       Backup by Shutting down Mongod Instance. We are using “ mongodump ” and “ mongorestore ” commands to Backup and Restore to MongoDB. Rename with Database Copy:- In this method, connect to MongoDB with “ mongo shell ”. Examples, > show dbs admin 0 . 000 GB local 0 . 000 GB mydb 0 . 000 GB > db.copyDatabase( "mydb" , "myNewDB" , "localhost" ) { "ok" : 1 } > use mydb switched to db mydb > db.dropDatabase() { "dropped" : "mydb" , "ok" : 1 } > show dbs admin 0 . 000 GB local 0 . 000 GB myNewDB 0 . 000 GB > use myNewDB switched to db myNewDB > db.users.find() { "_id" : ObjectId( "58...

3 Best Ways to DROP MongoDB Database [DROP]

“ How to DROP Database in MongoDB ”? “ How many types to DROP Database ”? In this section, I am going to describes “ DROP” or Delete MongoDB Database. Below version 3.4, does not provide any user interface like SQL Server or “Robomongo” but MongoDB 3.4 solve this problem with help of “ Robomongo Management Tool” . As per my understanding, it is a great achievement of MongoDB to provide us Robomongo Management Tool. You can download Robomongo MongoDB interface and install MongoDB & Robomongo in your machine and start to Create, Rename and DROP MongoDB database, collections, functions and Users. 3 Ways to “DROP” MongoDB Database:- 1.       “Use” of Robomongo Management Tool. 2.       “Use” Command Line. 3.       “Use” ASP.Net C# Code. Here you can decide to DROP MongoDb database, collections and users. “DROP” MongoDB Database Using Robomongo Tool:- You should go (download U...

MongoDB Export with $mongoexport

In the MongoDB, $mongoexport is used to take the backups of db tables (collections) in JSON, CSV and TSV format using the command. This command should be executed in the command prompt not in MongoDB clients. MongoDB Export command options:   - h < mongo - host - name >                     --This command is not required!   - u < user - name >                                   --This command is not required!   - p < password >                                    --This command is not required!   - d < db - name >                   ...

The Left Outer Join in MongoDB [$lookup Join]

“How to Join  query in MongoDB”? “How do I perform the SQL Join equivalent in MongoDB”? The  $lookup  is introduced in the  MongoDB  version 3.2  and it’s perform a “ Left Outer Join”  in the same database collection. The “ $lookup” stage does an equality match between a fields. The “ $lookup ” stage adds a new array field whose elements are the matching from the “ joined ” collection. The “ $lookup ” is an alternate way to implement Joins in MongoDB. Syntax: { $lookup: { from : “collection - to - join ”, localField: “Input - field - documents”, foreignField: “Input - field - from - documents - of - the - "from" - collection”, as : “Output - field - Array > } } Perform Joins using $lookup A collection Users contains { "_id" : 1001 , "name" : "Anil Singh" , "Age" : 32 , "Qualification" : "MCA...

MongoDB Date format

Date() : According to the MongoDB , date can be returns a string or object. Two Types 1.       Date() 2.       new Date() The Date() method is returns the current date as a string. For example, var date = Date();  //return date as a string The above date variable returns current date as a string. The new Date() method returns the current date as a Date object. You can specify different types of date format: 1.       new Date("YYYY-mm-dd") 2.       new Date("YYYY-mm-ddTHH:MM:ss") 3.       new Date("YYYY-mm-ddTHH:MM:ssZ") For example, var date = new Date ("2016-07-26T14:59:00Z"); //return date as date object The above date variable returns date as a date object.   How to use date in MongoDD query? db.customers.update( { _id: 1001 },   { $set: { name: "Anil" },    $setOn...

MongoDB $and and $or Operators

M ongoDb  OR ($or) O perator The $or operator are used to performs a logical OR operation on more than two expressions and returns all the match documents. Syntax:   { $or : [ { <expression 1> }, { <expression 2> }, .. , { <expression N> } ] } Query: db . customers . find ({         "$or" : [{ "Age": 30 },  { "Name": "Anil Singh" }] }); M ongoDb  OR ($or) AND AND ($and)  O perator The $and operator are used to performs a logical AND operation on more than two expressions and returns all the match documents. Syntax:   { $and : [ { <expression 1> }, { <expression 2> } , .. , { <expression N> } ] } Query: db . customers . find ({               $and : [                       ...

Angular 2 async pipe with ngFor loop

According to Angular 2 docs , “ Angular pipes, a way to write display-value transformations that we can declare in our HTML! ” Angular 2 templates use a special Async pipe to be able to render out Observables. Syntax:   *ngFor= "#obj of asyncObject | async | custom-Pipe: 'prop1' : 'prop2'" OR *ngFor= "#obj of (asyncObject | async)? .prop1? .prop2" For more detail, https://angular.io/docs/ts/latest/guide/pipes.html https://egghead.io/lessons/angular-2-rendering-an-observable-with-the-async-pipe

MongoDB Connection String UserName Password C#

According to MongoDB docs, “The mongodb  connection string username and password are optional. If username and password are specified in connection string , the client will attempt to log in to the specific database using the same credentials after connecting to the MongoDB instance .” Stayed Informed - MongoDB CRUD Operation in C#.NET The mongodb connection string URL's standard format and used to connect to MongoDB database server . mongodb: // [username:password@]host1[:port1][,host2[:port2] ,... [,hostN[:portN]]][/[database][?options]] Optional Parameters: ·          : port1 , ·          hostX , ·          : portX , ·          username: password@ Required Parameters: ·          mongodb: //, ·        ...