aspose file tools*
The moose likes MongoDB and the fly likes MongoDB Patterns Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » MongoDB
Bookmark "MongoDB Patterns" Watch "MongoDB Patterns" New topic
Author

MongoDB Patterns

Arjun Shastry
Ranch Hand

Joined: Mar 13, 2003
Posts: 1874
Welcome Rick,
One of the pattern/usage of MongoDB given is for Logging. In our system, logs are scattered on various boxes. In middleware too,various components like Adapters,java programs,webservices log to different locations. I belive MongoDB is the right choice for this kind of situation where logs can be consolidated. I wanted to know, if current applications are logging to files, how can that be changed to log to MongoDB ? We use proprietory software where default logging/exceptions are done to files.
Inbuilt gepspatial indexing is the main feature of MongoDB.Is there any advantage of using this over location based services provided by Microsoft/Yahoo! etc?


MH
Rick Copeland
author
Greenhorn

Joined: Apr 09, 2013
Posts: 17
    
    5
You have two basic options for logging to MongoDB. One is to modify your code to log to MongoDB. Another option is to have a separate process that runs periodically (perhaps at log rotation time) to aggregate the log files into MongoDB. The second approach has the advantage of not requiring any changes to your existing applications, but it does mean that the log data in MongoDB will be somewhat out-of-date.

As for geospatial indexing, I'm not sure of anything that Microsoft/Yahoo may have, so I'll constrain my comments to what MongoDB does. MongoDB does not contain any map data (unless you put some in). The geospatial indexing in MongoDB allows you to store geospatial coordinates (longitude and latitude) for different objects and then execute queries like "find objects in a certain collection, sorted by how close they are to a certain point" or "find all the objects with coordinates that fall within a particular circle" -- things like that.

I hope that helps!
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Arjun,

What is the rationale for logging to mongodb ? Is it the amount of data or unstructed data.


Groovy
Arjun Shastry
Ranch Hand

Joined: Mar 13, 2003
Posts: 1874
Amount of data and speed. Capping concept in MongoDB makes sure servers don't run out of memory. MongoDB i guess faster in reading and writing the data than RDBMS. MongoDriver be default won't wait for write to complete on server.In such case, there may be chance of losing the data incase of failure but thats ok for us.Even if you lose 10 logs out of 10,0000, it won't be much problem.
Arjun Shastry
Ranch Hand

Joined: Mar 13, 2003
Posts: 1874
Rick Copeland wrote:You have two basic options for logging to MongoDB. One is to modify your code to log to MongoDB. Another option is to have a separate process that runs periodically (perhaps at log rotation time) to aggregate the log files into MongoDB. The second approach has the advantage of not requiring any changes to your existing applications, but it does mean that the log data in MongoDB will be somewhat out-of-date.

As for geospatial indexing, I'm not sure of anything that Microsoft/Yahoo may have, so I'll constrain my comments to what MongoDB does. MongoDB does not contain any map data (unless you put some in). The geospatial indexing in MongoDB allows you to store geospatial coordinates (longitude and latitude) for different objects and then execute queries like "find objects in a certain collection, sorted by how close they are to a certain point" or "find all the objects with coordinates that fall within a particular circle" -- things like that.

I hope that helps!

Thanks Rick.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

ok cool. Also i think mongo db does not support ACID properties of transactions, this may speed up db operations
Rick Copeland
author
Greenhorn

Joined: Apr 09, 2013
Posts: 17
    
    5
Pradeep bhatt wrote:ok cool. Also i think mongo db does not support ACID properties of transactions, this may speed up db operations


This is true; MongoDB performs atomic operations, but they are limited to a single document.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

oh. so mongodb cannot be used in transactional applications like banking.
Rick Copeland
author
Greenhorn

Joined: Apr 09, 2013
Posts: 17
    
    5
Well, the question of whether you really need transactions in banking is actually an interesting one... generally, banks do not use ACID transactions for everything; they instead use methods to bound the risks of inconsistency and perform periodic reconciliation of their legers. For instance, it's important to a bank that you be able to withdraw funds from an ATM even if that ATM cannot connect to the server, so they typically put a limit of $500 or so on withdrawals from an ATM. So it's possible to overdraw an account, but not by much.

My book has a specific example in the ecommerce chapter describing how you can implement transaction-like guarantees (in this case, for inventory management) using a technique that I call optimistic update with compensation.

If you really need ACID transactions, you can actually build a 2-phase commit structure atop MongoDB collections; I show how to this in chapter 3, IIRC. I will warn you, however, that it's really easy to forget an edge case when you're building something like this, so if you can restrict your atomic updates to a single document, you'll be much less likely to make a mistake.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MongoDB Patterns