Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

From MongoDB to Google Cloud Datastore

I'm figuring out if it would be easy to move my already existing app towards a Google Cloud Datastore. Currently it exists in MongoDB so it would be from NoSQL to NoSQL, but it does not seem that it would be easy. An example. My app uses a hierarchy of objects which is why I like MongoDB because of its elegance:

{
"_id" : "31851460-7052-4c89-ab51-8941eb5bdc7g",
"_status" : "PRIV",
"_active" : true,
"emails" : [
  { "id" : 1, "email" : "[email protected]", "_hash" : "1514e2c9e71318e5", "_objecttype" : "EmailObj" },
  { "id" : 1, "email" : "[email protected]", "_hash" : "78687668871318e7", "_objecttype" : "EmailObj" }
  ],
"numbers": [
...
],
"socialnetworks": [
...
],
"settings": [
...
]
}

While moving towards Google Cloud Datastore, I can save emails, numbers, socialnetworks, settings, etc as a string, but that defeats the whole purpose of using JSON as I will lose the opportunity to query this. I have a number of tables where I have this issue.

Only solution I see is to move all of these to different entities (tables). But in that case the amount of queries will increase, and therefore also the cost. Other solution might be to keep only arrays of ids and do key-value like resolves on Google Cloud Datastore which are free (except traffic maybe).

What is the best approach here?

like image 798
spa900 Avatar asked Jul 05 '17 15:07

spa900


People also ask

Can I use MongoDB on Google Cloud?

Run MongoDB Atlas, a fully managed developer data platform, on Google Cloud in just a few clicks. Set up, scale, and operate MongoDB Atlas anywhere in the world with the versatility, security, and high availability you need to build and manage any application.

How do I connect my MongoDB database to the cloud?

To connect to a MongoDB, retrieve the hostname and port information from Cloud Manager and then use a MongoDB client, such as mongosh or a MongoDB driver, to connect. To connect to a cluster, retrieve the hostname and port for the mongos process.

Is MongoDB a database or a Datastore?

MongoDB is a NoSQL database management application. NoSQL database systems offer an alternative to traditional relational databases using SQL (Structured Query Language). Data is stored in tables, rows, and columns in a relational database, with relationships between entities.


2 Answers

The transition from Mongo to Google's Datastore would not be trivial. A big part of the reason for this is that Datastore (although technically still NoSQL) is a columnar database whereas Mongo is a traditional NoSQL. Just as SQL databases require a different mindset from NoSQL databases, columnar databases require a different mindset again.

The transition from NoSQL to Datastore would require a comprehensive restructuring of your data.

like image 140
James Avatar answered Oct 07 '22 00:10

James


You don't have to save everything in a string. Datastore has what is called Embbebed Entity, which looks very much like in Mongo. Just a full object into another.

Check some library like Objectify which makes it very easy to interact with datastore.

like image 25
Wrong Avatar answered Oct 07 '22 00:10

Wrong