Posts

Showing posts with the label MongoDB

How to update a collection via mongoimport in MongoDB?

You can update a collection via mongoimport in MongoDB --upsert provide you the facility to update the data on basis of _id in MognoDB collection Take a look on this post here you can learn how to import and export the data from MongoDB http://web-developers-solution.blogspot.in/2015/01/how-to-import-and-export-data-from-MongoDB-in-json-format.html After take the backup from MongoDB you can change the data from document but keep in mind do not change the _id Now like you have imported a collection from mongoDB named user.json Open the file and make your changes and the save the file Now you can import the file it will update your document on the basis of _id in documents mongoimport --collection profiles --db backup --upsert --file user.json

How to import and export the data from MongoDB in json format?

You can use these query to import and export the data from MongoDB in JSON format. First of all you need to install MongoDB in your system. Then open cmd with administrator Now go to mongodb bin directory like C:\wamp\bin\mongodb\mongodb-win32-x86_64-2008plus-2.4.12\bin Then run this command Query to Export mongoexport --db databasename --collection collectionname --out filename.json Now you need to import the data from your file which you have backup recently Query to Import mongoimport --collection collectionname --db databasename --file filename.json By use these query you can import and export the data from mongoDB in json format Now if you have to use these query then use same process to import and export Then open cmd with administrator  and then run these command with your mongoDB details Query to import mongoimport --host hostname --port 27017 --username yourusername --password yourpassword --collection collname --db dbname --file filename.json Upda

What is fixtures in Meteor?

Fixtures in Meteor Basically in short fixtures is js file where you can set default data which will insert automatically when the app runs. Like when you created a app and you want that when you will reset your database or delete all record from database then by default some record became inserted in collection of mongodb. like you can add some data in fixtures if (user.find().count() === 0) {   user.insert({     "name": "Industria de Diseno Textil SA",     "country": "ES",     active:false   });   userinsert({     "name": "Under Armour Inc.",     "country": "US",     active:false   });   user.insert({     "name": "Nike Inc.",     "country": "US",     active:false   }); }  So as you set code in fixures that will check if user collection does not have any record then by default it will insert three record when app

How to write MongoDB query in Meteor?

How to write MongoDB find query in Meteor? Or  How to write MongoDB update query in Meteor? First of all find query  Select symbol.yahoo from user where active='true' user.find({active:true},{fields:{'symbol.yahoo':1}}); Update query in MongoDB Meteor update user set open_at=9pm and trade_date ='2012-12-20' where symbol.yahoo='meteor'  var updata = {             open_at : '9pm',             trade_date : '20122-12-30' } user.update({'symbol.yahoo':'meteor'}, {$set:updata});

How to rename a field from a collection in mongoDB?

How to rename a field from a collection in mongoDB? By this query you can rename a field from whole collection in mongoDB db.colleciton.update(     //  where query like: where active="yes"     {         "active" : "yes"     },       // will remove Name field from current collection     {         $rename: {"Name":"Username"}     },       // options     {         "multi" : true  // update all document     } ); or you can copy and paste this code above code is with comment that how mongoDB query works db.colleciton.update(     {         "active" : "yes"     },     {         $rename: {"Name":"Username"}     },     {         "multi" : true     } );

How to remove a field from a collection in mongoDB?

How to remove a field from a collection in mongoDB? By this query you can remove a field from whole collection in mongoDB db.colleciton.update(     //  where query like: where active="yes"     {         "active" : "yes"     },         // will remove Name field from current collection     {         $unset: {"Name":""}     },         // options     {         "multi" : true  // update all document     } ); or you can copy and paste this code above code is with comment that how mongoDB query works db.colleciton.update(     {         "active" : "yes"     },     {         $unset: {"Name":""}     },     {         "multi" : true     } );

How To install MongoDB in ubuntu?

How To install MongoDB in ubuntu   step1: Open the terminal login with root and copy the given code past in terminal apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10 echo "deb http://downloads-distro. mongodb.org/repo/ubuntu- upstart dist 10gen" | tee -a /etc/apt/sources.list.d/10gen. list apt-get -y update apt-get -y install mongodb-10gen step2: $ sudo service mongodb start ******************** setup with php *************** step 1: sudo apt-get install php5-dev php5-cli php-pear step2 : sudo pecl install mongo step3: open php.ini "/etc/php5/apache2/php.ini" and set "extension=mongo.so" step4: service apache2 restart Now php with mongodb is ready for work.

How to add new field to all documents in mongoDB?

As you know that mongoDB have a update function which have four parameter to pass. You can use this like below: db.coll.update({}, $set:{name:"value"}, false, true);   You can set condition too: db.coll.update({_id:12}, $set:{name:"value"}, false, true);

How to create an Auto-Incrementing field in MongoDB?

Create an Auto-Incrementing  I checked so many article related to this but all are confusing for me because i was new in MongoDB and i want to create a field which should be auto increment like MySql. So i got an article on docs.mongodb.org and find that this article is great Here are some steps that how you can create an auto-increament id in your MongoDB Open your MongoDB screen where you write command line query Run this command and check database Step 1. show dbs - This command will show all database from your MongoDB Step 2. use databasename -  choose your database where you want to create a collection and auto increment field Now create new collection Step 3. db.createCollection("user"); Step 4. db.counters.insert(    {       _id: "userid",       seq: 0    } ) Now you need to create a function for auto increment the _id in mongoDB so create a function in your mongodb You need to write this function on your mongoDB scree

MognoDB Tutorial

Image
MognoDB Tutorial - Chapter 1 MongoDB is an open-source document database, and leading NoSQL database. MongoDB is written in c++. I am going to tell you that how can you learn MongoDB: TAKE A LOOK ON THIS TABLE FOR A SIMPLE BRIEF RDBMS MongoDB Database Database Table Collection Tuple/Row Document Column Field Table Join Embedded Documents Primary Key Primary Key (Default key _id provided by mongodb itself) Database Server and Client Mysqld/Oracle mongod mysql/sqlplus mongo First step:   You need to go in MongoDB folder where you had installed it Like: C:\wamp\bin\mongodb\mongodb-win32-x86_64-2008plus-2.4.10\bin Now you need to start mongodb server to double click on mongod.exe if it is already start if will blink the cmd and close. Now you need to Double click on mongo.exe to cmd interface to run mongoDB command It will show something li