What is MongoDB?
MongoDB is a NoSQL database that can be successfully used in modern, complex applications. It stores data in flexible, JSON-like documents. With a document model, MongoDB is simple for developers to learn and use. Even if it is easy to use, it still provides all the features that are required in complex projects.
A record in MongoDB is a document, structured data is stored in the document as a field and value pair.
{
"_id" : "5d270bab9a0c053494dfb5e5",
"GenericAttributes" : [],
"ProductTypeId" : 5,
"Name" : "Build your own computer",
"SeName" : "build-your-own-computer",
"ShortDescription" : "Build it",
...
}
In this article, you will learn how we handle eCommerce data in our based on MongoDB ecommerce – GrandNode.
eCommerce Data in MongoDB
Product Catalog
A product catalog is nothing more or less than a collection of all data related to products, categories, brands, product reviews, and in a nutshell, everything that is available for sale in your store.
Catalog data usually contains the following data:
- SKU
- Price
- Product name
- Product description
- Quantity
- Catalog mapping (categories, collections, brands)
- Product reviews
Example of Product collection from GrandNode, our NoSQL open-source eCommerce platform:
{
"_id" : "5d270bab9a0c053494dfb5e5",
"GenericAttributes" : [],
"ProductTypeId" : 5,
"Name" : "Build your own computer",
"SeName" : "build-your-own-computer",
"ShortDescription" : "Build it",
...
}
Shopping Cart Data
The shopping cart gives users the possibility to select and purchase items from the product catalog. It’s one of the fundaments of eCommerce. In GrandNode, shopping cart data (and wishlist data) is a part of Customers collection. You can find that information on every customer, just look for the "ShoppingCartItems" : [], field.
{
"ShoppingCartItems" : [
{
"_id" : " ",
"StoreId" : " ",
"WarehouseId" : null,
"ShoppingCartTypeId" : 1,
"ProductId" : " ",
"Attributes" : [],
"EnteredPrice" : null,
"Quantity" : 1,
"RentalStartDateUtc" : null,
"RentalEndDateUtc" : null,
"CreatedOnUtc" : ISODate("2021-07-29T09:56:46.732Z"),
"UpdatedOnUtc" : ISODate("2021-07-29T09:56:46.732Z"),
"IsFreeShipping" : false,
"IsGiftVoucher" : false,
"IsShipEnabled" : true,
"AdditionalShippingChargeProduct" : 0.0,
"IsTaxExempt" : false,
"ReservationId" : "",
"Parameter" : "",
"Duration" : "",
"cId" : null
}
]
}
Customer Data
Customer data is one of the most important parts of every eCommerce. It contains sensitive data, it contains a lot of data related to your customers' orders.
{
"_id" : "60b4a9c2a5556de7b1509696",
"UserFields" : [],
"OrderGuid" : LUUID("6370faba-eb20-6a4e-b3e9-80153d72b4b0"),
"OrderNumber" : 1,
"Code" : "4HCYYEFQ",
"StoreId" : "60b49fcc692073f53126ff1d",
"CustomerId" : "60b49fcc692073f531270078",
"OwnerId" : "60b49fcc692073f531270078",
"SeId" : null,
"PickUpInStore" : false,
"OrderStatusId" : 30,
"ShippingStatusId" : 40,
"PaymentStatusId" : 30,
"PaymentMethodSystemName" : "Payments.CashOnDelivery",
"PaymentOptionAttribute" : null,
"CustomerCurrencyCode" : "USD",
"PrimaryCurrencyCode" : "USD",
"CurrencyRate" : 1.0,
"Rate" : 1.0,
[...]
}
Order Data
Order collection stores data about every transaction that is made in your store. It contains information about pending, processing orders and also all orders that have been completed.
In order collection, you will find information such as:
- email of customer,
- order status,
- billing address,
- shipping address,
- payment method,
- shipping method,
and many more. Below you can find an example of it:
{
"CustomerEmail" : "admin@yourstore.com",
"FirstName" : null,
"LastName" : null,
"OrderSubtotalInclTax" : 1800.0,
"OrderSubtotalExclTax" : 1800.0,
"OrderSubTotalDiscountInclTax" : 0.0,
"OrderSubTotalDiscountExclTax" : 0.0,
"OrderShippingInclTax" : 0.0,
"OrderShippingExclTax" : 0.0,
"PaymentMethodAdditionalFeeInclTax" : 0.0,
"PaymentMethodAdditionalFeeExclTax" : 0.0,
"OrderTax" : 0.0,
"OrderDiscount" : 0.0,
"OrderTotal" : 1800.0,
"PaidAmount" : 1800.0,
"PaidDateUtc" : ISODate("2021-05-31T09:18:54.588Z"),
"RefundedAmount" : 0.0
}
Payment Transactions
In one of our blog posts, you were able about a new way of order processing. We’ve introduced payment transactions and since GrandNode 2.0, it stores data related to payment.
In GrandNode we don't store sensitive credit card data, payment providers are responsible for it. If you want to keep them in your database, remember about encrypting.
Example of a payment transaction:
{
"_id" : " ",
"UserFields" : [],
"PaymentMethodSystemName" : "Payments.CashOnDelivery",
"TransactionStatus" : 20,
"StoreId" : "60b49fcc692073f53126ff1d",
"OrderGuid" : LUUID("6370faba-eb20-6a4e-b3e9-80153d72b4b0"),
"OrderCode" : "4HCYYEFQ",
"CustomerId" : "60b49fcc692073f531270078",
"CustomerEmail" : "admin@yourstore.com",
"CurrencyCode" : "USD",
"CurrencyRate" : 1.0,
"TransactionAmount" : 1800.0,
"PaidAmount" : 1800.0,
"RefundedAmount" : 0.0,
"IPAddress" : "::1",
"AuthorizationTransactionId" : null,
"AuthorizationTransactionCode" : null,
"AuthorizationTransactionResult" : null,
"CaptureTransactionId" : null,
"CaptureTransactionResult" : null,
"Description" : null,
"AdditionalInfo" : null,
"CustomValues" : {},
"Errors" : [],
"CreatedOnUtc" : ISODate("2021-05-31T09:17:54.850Z"),
"UpdatedOnUtc" : null,
"Temp" : false
}
If you want to learn more about using payment transactions, you should definitely check out a blog post.
Content Data
Content data is related to all stuff around content management, like blogs, message templates, news sections, knowledgebase, courses.
Example from blog collection:
{
"_id" : "60b49fd1692073f531271b24",
"UserFields" : [],
"Title" : "How GrandNode became the real open-source e-Commerce platform?",
"PictureId" : null,
"Body" : "<p>Body of the post</p>",
"BodyOverview" : "<p> Body overview </p>",
"AllowComments" : false,
"CommentCount" : 0,
"Tags" : "e-commerce, blog, moey",
"StartDateUtc" : null,
"EndDateUtc" : null,
"MetaKeywords" : null,
"MetaDescription" : null,
"MetaTitle" : null,
"LimitedToStores" : false,
"Stores" : [],
"Locales" : [],
"SeName" : "how-grandnode-became-the-real-open-source-e-commerce-platform",
"CreatedOnUtc" : ISODate("2021-05-31T08:35:29.226Z")
}
Example from news collection:
{
"_id" : " ",
"UserFields" : [],
"Title" : "About Grandnode",
"PictureId" : null,
"SeName" : "about-grandnode",
"Short" : " Short description ",
"Full" : "<p> Body of the news </p>",
"Published" : true,
"StartDateUtc" : null,
"EndDateUtc" : null,
"AllowComments" : false,
"CommentCount" : 0,
"LimitedToStores" : false,
"Stores" : [],
"Locales" : [],
"MetaKeywords" : null,
"MetaDescription" : null,
"MetaTitle" : null,
"CreatedOnUtc" : ISODate("2021-05-31T08:35:29.247Z"),
"LimitedToGroups" : false,
"CustomerGroups" : [],
"NewsComments" : []
}
Example from message templates:
{
"_id" : " ",
"UserFields" : [],
"Name" : "AuctionEnded.CustomerNotificationWin",
"BccEmailAddresses" : null,
"Subject" : "{{Store.Name}}. Auction ended.",
"Body" : "<p>Hello, {{Customer.FullName}}!</p><p></p><p>At {{Auctions.EndTime}} you have won <a href=\"{{Store.URL}}{{Auctions.ProductSeName}}\">{{Auctions.ProductName}}</a> for {{Auctions.Price}}. Visit <a href=\"{{Store.URL}}/cart\">cart</a> to finish checkout process. </p>",
"IsActive" : true,
"DelayBeforeSend" : null,
"DelayPeriodId" : 0,
"AttachedDownloadId" : null,
"EmailAccountId" : " ",
"LimitedToStores" : false,
"Stores" : [],
"Locales" : []
}
GridFS
GridFS is a specification for storing and retrieving files that exceed the BSON-document size limit of 16 MB. Instead of storing a file in a single document, GridFS divides the file into parts, or chunks and stores each chunk as a separate document. That's why in the database of your store, you will find two collections fs.files and fs.chunks.
We use GridFS in our MongoDB e-commerce to store attachments that you upload to the store.
How do we store pictures in MongoDB?
Pictures are stored in the Picture collection. We keep them as a binary. In MongoDB, binaries can have 4MB size.
By default, GrandNode - MongoDB eCommerce, stores pictures in the file system. If you want to store them in the database, you just need to edit the Media settings in the Admin panel.
Example of Picture collection element:
{
"_id" : "5d270baa9a0c053494dfb5a1",
"GenericAttributes" : [],
"PictureBinary" : { "$binary" : "[base64 binary]", "$type" : "00" },
"MimeType" : "image/jpeg",
"SeoFilename" : "computers",
"AltAttribute" : null,
"TitleAttribute" : null,
"IsNew" : false
}
What about transactions in MongoDB?
Many people bring up MongoDB’s lack of transactions across collections as evidence that it’s not suitable for e-commerce applications. To be honest since our first release in 2015 and through a lot of finished projects, it wasn't a problem and limitation so far.