How MongoDB makes custom e-commerce simple

Source: Internet
Author: User
Tags button type mongodb query zen cart

The open-source e-commerce software market has gone through many stages of development. You may have some knowledge through popular platforms such as oscommerce, magento, Zen cart, prestashop, and spree. These platforms are often used as the basis for customized e-commerce software and require an SQL database. Because open-source software has inherent challenges in adapting to custom functions, it seems that MongoDB will play an important role in the next development and evolution of e-commerce.

Kyle banker was the first to post blogs on MongoDB and e-commerce in April 2010. It was rare to come out after that.Article. In his blog, Kyle wrote about magento and other SQL-based platforms: "What you will see is that a large number of tables work together, A flexible structure is provided for the database system in an inflexible type."

In this regard, we must ask why flexible structures are so important in e-commerce?

Open-source platforms mean that they can adapt to many different designs, conversion flows, and business processes. A flexible structure can help developers associate Custom Data Structures with existing models of the platform. Without a flexible structure, developers must overcome many obstacles to implement certain special functions. When the cost of creating and maintaining custom functions is too high, you can choose to abandon the function, start again with another platform, or create a platform based on the draft. These are expensive proposals.

There are better methods

After several years, we have been developing forward, a new open-source e-commerce platform that works with MongoDB. Since March 2012, it has been put into production and used, and finally confirmed that we can demonstrate the advantages of the unstructured Design of MongoDB for the development of custom functions.

The following example shows a similar ORM Convention of forward and other platforms. It is provided only in the platform itself, but its basic concept is directly mapped to the file structure of MongoDB. In this case, consider using get () as the DB. collection. find ()-put () as insert/update ()-post () as insert ()-delete ()... Delete ().

Faster prototyping

Most e-commerce websites represent small companies. efficient execution is the most important aspect of the network platform. When the flexible file structure of MongoDB is executed through the model interface of the platform, it is easier to add custom fields than ever before.

For example, let's assume that you need a simple view to manage multiple Custom Attributes added to the product. The following is a basic example to achieve this purpose, written in the forward template syntax:

{ARGs $ product_id} {if $ request. post} {$ Product = put ("/products/$ product_id", [spec => $ Params. SPEC, usage => $ Params. usage])} {flash notice = "saved" Refresh = true} {else} {$ Product = get ("/products/$ product_id ")} {/if} <for method = "Post"> <Div class = "field"> <label> product specification </label> <textarea name = "spec" >{$ Product. spec | escape} </textarea> </div> <Div class = "field"> <label> product usage instructions </label> <textarea name = "usage" >{$ product. usage | escape} </textarea> </div> <button type = "Submit"> Save product </button> </form>

The role of this template may be obvious, but it is not obvious that the platform does not know anything about the "spec" or "usage" field, however, they are treated in a way that e-commerce data models are designed for them. Database migration is not required at all, onlyCodeYes.

You may argue that this can be achieved through fuzzy SQL database structure, or you may be right, but it is not perfect for standard database tools or cannot be read. Ad-hoc queries on custom fields will become very difficult.

Query on custom Fields

If we need a custom key/value storage, you may not benefit too much from the flexible structure. What truly shines on MongoDB is its ability to query any file field (or even embedded files.

 
{Get $ oversized_products from "/products" [oversized => true, active => true]}

There are super large products in the {$ oversized_products.count} activity.

These fields may not be known to the e-commerce API, but in this case, the MongoDB query syntax can only find files with matching fields.

No longer related to complexity

This is a big change for those who spend years writing relational SQL queries. How do we create a data relationship without a connection? There are many different strategies, but forward defines a field as a static value or a callback method. This allows one field to return another file or set based on the query. The result is a data model that allows you to browse relationships without connection. For example (PHP ):

 
// Class accounts extends appmodel... $ this-> fields => array (... 'Orders '=> function ($ order) {return get ("/orders ", array ('account _ id' => $ account ['id']);});

This relationship can be used in a template similar to the following:

 
{Get $ account from "/accounts/$ session. account_id "}

You have processed

<Table> {foreach $ account. orders as $ order} <tr> <TD >#{ $ order. id} </TD> <TD >$ {$ order. sub_total }</TD> <TD >$ {$ order. grand_total }</TD> <TD> {$ order. items | count} item (s) </TD> </TR >{/ foreach} </table>

Relationships can be defined through simple or complex queries. The result is delayed loading, which makes this example possible:

 
{Get $ order from "/orders/123"} {$ order. account. name} placed {$ order. account. orders. count} orders since {$ order. account. orders. first. date_created | date_format} // output: John Smith placed 3 orders since Jun 14,201 2
How about transactions?

Many people have suggested that MongoDB lacks atomic transactions as evidence in collection and is not suitable for e-commerce applications. So far, this has not been an important obstacle in our experience.

There are other methods to achieve data integrity. In systems with medium/low data conflicts, optimistic locks are adequate. We will share more details about these strategies later.

Summary

With MongoDB, the future of e-commerce software is bright. It is time to find another path. The revolving structure, complex relational queries, and feared database migration have all become a thing of the past. If you are interested in cooperating with forward before the public release, please consider joining the private test to help us repeat open-source e-commerce to the status that we originally knew.

For a guest post from developer/creator Eric Ingram, follow @ getfwd

 

Original article:How MongoDB simplifies e-commerce

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.