Showing posts with label mongodb. Show all posts
Showing posts with label mongodb. Show all posts

Wednesday, April 4, 2012

What is the difference between MongoDB Relplica Sets and Master-Slave Replication?

Replica Sets and Master-Slave are alternatives for achieving replication in MongoDb. The original implementation was Master-Slave until version 1.6 onwards which contained the Replica Set feature. From then on, Replica Set is a functional superset of the Master-Slave setup which supports asynchronous replication, automatic failover and automatic recovery of a member node. Things that master/slave didn't originally support.

It is therefore recommended that replica sets are used instead of master/slave setup to achieve replication for production environments using MongoDb.

For more info on MongoDb Replica Sets, click here.
For more info on MongoDb Master/Slave, click here.



Tuesday, September 6, 2011

Uncaught exception 'MongoCursorException' with message 'invalid query'

Another nasty MongoDb exception that's hard to detect if everything had been working earlier. The more you have progressed without noticing this, the more you will have to fix which could have been prevented. So, if you landed here, most likely you have the same problem I had.

What's the problem?

Tuesday, August 30, 2011

Mongo: Invalid Modifier Specified{$var}

This is an exception thrown by MongoDB server when you mix the modifier "$set" with a normal variable during the update process. This is both observed in the shell and PHP Mongo. This is due probably to the difference in behavior of update that when you use "$set" would only partially update the object and the latter (using a common field/variable) would actually overwrite the entire document object which is a functionality conflict.

Monday, May 23, 2011

Updating Records in MongoDb

Few important notes to remember when updating records in MongoDb

1. Multi update only works with $ operators
2. You can use upsert to update old items and insert new items
3. Updating without a $ operator like $set, $inc replaces the entire document.
4. In the time of writing, the default is a single update even a given criteria matches more records. You must explicitly specify multi = true, multiple = true depending on the client / driver you're using.
5. It is recommended then to explicitly mention whether you want to update one or more records.
6. You can use safe or fsync to make sure that the update is successful before returning to the driver/client.

Wednesday, March 16, 2011

New Yum Repo for MongoDb

As of February 2011, 10gen has new repositories for getting there latest version. The old repositories still would work but only up to 1.6.5. Here's the new configuration files.
To add the configuration,
# vi /etc/yum.repos.d/10gen.repo , then paste the following information (use only one appropriate for your server)

For CentOS 5.4 and Fedora on x86_64(64-bit)
#------ copy after this line --------
[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0
#------ end copy --------- 

For CentOS 5.4 and Fedora on x86(32-bit)
#------ copy after this line ---------
[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686
gpgcheck=0
#------ end copy ---------

Monday, March 7, 2011

Understanding PHP Mongo

MongoDb, a NoSQL database management system, uses a PECL(PEAR Extension Class Library)  called PHP Mongo as a driver to interact with the MongoDb server. If you have pear installed, it so easy to add it to your PHP (i.e pecl install mongo) and you only have to activate it as part of your PHP modules. Setting aside the "download and installation" of PHP Mongo, let us see the what it can do for you.

Saturday, January 22, 2011

Fatal error: Uncaught exception 'MongoConnectionException' with message 'connecting to mongodb://localhost:27017 failed: Permission denied'

You've been working with MongoDB in the CLI for so long and then you suddenly require your work taken to the web. But then BAAAAM!, you encounter this nasty little fatal error.
Fatal error: Uncaught exception 'MongoConnectionException' with message 
'connecting to mongodb://localhost:27017 failed: Permission denied'
Could be even worse if you are blanket catching exceptions, even with E_STRICT and all without properly returning the exceptions could take you some work to figure out what's wrong. I encountered this issue while installing PHPMoAdmin and I keep getting the "Cannot Connect To Database" message. So I wrote this article with the intention of showing not just the fix but the root cause as well.

Thursday, September 2, 2010

UPSERT To Database - A Great But Not Common DBMS Feature

UPSERT is the combination of update and insert. The idea behind it is that if you are trying to update an item from a database but doesn't exist then insert it.

So how does this benefit developers?

For one thing, you only have to write one feature to store and update the database promoting code consistency and efficiency. In addition, since it's only one feature you can potentially save transactions to the database for applications that require checking the database prior to updating or inserting. Which is exactly what we want in terms of optimization and it just makes things simpler so developers can focus more on "business" stuff. Moreover, since it is just one statement, it reduces the amount of log noise and chances of errors usually encountered when storing duplicate items or trying to update missing items which is altogether good for replication and system stability.

Tuesday, August 31, 2010

Mongodb Data Types


These are the usable Mongodb Data Types. The "Type Number" can be used together with your MongoDb queries utilizing the conditional operator: '$type'.  Whereas, the "Type Name" is a non-terminal data type (as is) as specified in the BSON specifications.

Type Name Type Number
Double 1
String 2
Object 3
Array 4
Binary data 5
Object id 7
Boolean 8
Date 9
Null 10
Regular expression 11
JavaScript code 13
Symbol 14
JavaScript code with scope 15
32-bit integer 16
Timestamp 17
64-bit integer 18
Min key 255
Max key 127 

Sample usage:
db.things.find( { a : { $type : 2 } } ); // matches if a is a string
 db.things.find( { a : { $type : 16 } } ); // matches if a is an int
More Information on MongoDb Data Types

Saturday, August 7, 2010

MongoDb 1.6 Released - Scaling Production Ready At Last!!!

With the release of the MongoDB version 1.6 Stable, which focuses in scaling, this rockin' DBMS just made sharding and replica sets production ready.

What does it mean?

It means that you can now rely on Mongodb to:

1. Shard when the need arises.
2. Add servers to your cluster at zero downtime.
3. Single point-of-failure is no longer a problem making your systems highly available.
4. Replication lag, reduced dramatically if not totally.


Wednesday, July 7, 2010

Zend Framework, and Mongo DB - Seamless Integration

I decided to create a Zend Framework compatible PHP class library that can do the following:

1. Easily integrate the PHP drivers to Zend Framework

Thursday, May 20, 2010

Yum Install MongoDb (RPM package) on CentOS/RHEL and Fedora

To all users of MongoDb out there, you're life has been made easier. Mongodb is now distributed as a RPM package and it comes together with a yum repo. Cool huh?

Okay, so before we discuss how it's done, let's add the details to your yum configuration first. If you're using RHEL / CentOS, the repo configurations are usually located at /etc/yum.repos.d.