better approach to load referential data - neo4j

I have entities related to cities in my Neo4j graph. I've created a form in which a user can create an entity, let's say a shop. In this form, I would like the user to choose the city of the shop from a combo box. I'm wondering what is the best approach : get all the cities from the graph with a cypher query or have all the cities (and other referential data) in another database (relational or nosql or whatever), and then populate my comboboxes ? Or is there a better approach ?
Thanks for your time,
Didier

I've just heard of polyglot persistence and read some articles. Should it be, in my case, the best approach to store cities and shops in a document database and then use my graph database to add relationships with customers, shops and cities?

Related

Solr join across multiple collections and fetch data from both collections

I have 2 solr collections:
Ads {id, title, body, description, etc etc)
AdPlacement (ad_id, placement_id, price)
Each Ad can have 500-1000 placements, with different prices.
The search usecase is where I have a placement and some search keyword and I want to find the Ads that map the keyword provided in the title/body/description fields and it should be sorted by the price in the AdPlacement collection for the given placement. We would like to get the Ad details and the price in the output returned.
Is there any way to achieve this in solr using join across multiple collections? What I have read so far says you can only get data from one collection and use the other one just for filtering.
Solr is a Document database and supports nested documents so ideally you would want to model such that your add placement records are a part of the Ad document. This would be the better way to handle your scenario. Please go through this blog Solr Nested Objects and the relevant Solr documentation
In case modifying the document structure is not an option then consider this documentation which mentions about allowing some level of join between collections.

Automatic denormalizing by query

I wonder if it's possible to create a logic that automatically creates a denormalized table and it's data (and maintains it) by a specific SQL-like query.
Given a system where the user can maintain his data model and data. All data are stored in "relational" tables, but those tables are only used for the user to maintain his data. If he wants to display data on a webpage he has to write a query (SQL) which will automatically turn into a denormalized table and also be kept up-to-date when updating/deleting the relational data.
Let's say I got a query like this:
select t1.a, t1.b from t1 where t1.c = 1
The logic will automatically create a denormalized table with a copy of the needed data according to the query. It's mostly like a view (I wonder if views will be more performant than my approach). Whenever this query (give it a name) is needed by some business logic it will be replaced by a simple query on that new table.
Any update in t1 will search for all queries where t1 is involved and update the denormalized data automatically, but for performance win it will only update the rows infected (in this example just one row). That's the point where I'm not sure if it's achievable in an automatic way. The example query is simple, but what if there are queries with joins, aggregation or even sub queries?
Does an approach like this exist in the NoSQL world and maybe can somebody share his experience with it?
I would also like to know whether creating one table per query does conflict with any best practises when using NoSQL databases.
I have an idea how to solve simple queries just by finding the involved entity by its primary key when updating data and run the query on that specific entity again (so that joins will be updated, too). But with aggregation and sub queries I don't really know how to determine which denormalized table's entity is involved.

Rails: Adding new column to certain entries of database

I'm trying to make an online marketplace Rails App and I wanted to add a new column to my database conditional on another column.
I have a rails model "listings", which contains fields: "name, price, description, category." There are several categories: e.g., "Apartments, Books, Electronics,..." I want to add "Lat" and "Lon" geolocation columns only for Apartment listings. Would this be possible? How would I go about it?
I'm new to Ruby, so I apologize if this is a really easy question.
Thanks!
#Saraf answer nails it pretty much. Well, this is the case that you consider you have a SQL database. If you want to use a NoSQL database, such as MongoDB, you can store whatever you want inside collections (think about it as storing JSON objects).
Edit: clarification
You use SQL DB and you need to think about your relational schema and how you will handle different data (inheritance, for instance).
You use NoSQL DB and you can store "JSON objects" freely in your collections.
Since a model is a table, all the records will have the same attributes.
You can let them nil for other categories than apartments (and keep only one model), or you can create an herited model Apartments from Listings (http://api.rubyonrails.org/classes/ActiveRecord/Inheritance.html).

Neo4j cypher query simulate sql join query

I have two different kinds of node entities without any relationships between them, i wonder how to write a cypher query to join these two node entities by common property?
For example, if i want to return a blog by passing blogId as a parameter, but i also want to return creator username by joining user entity. Is it possible? Thanks in advance.
Why don't you have a relationship between user and blog? As far as graph dbs are concerned to connect data, this will help you to get users' blogs. Further, you can connect the blogs according to their topics etc.

How we design Dynamo db with keep relation of two entity

Hi iam new in dynamo db and, with my knowledge its a non relational db ie we cant join the tables. My doubt is how we design the table structure. Please clarify with following example.
I have a following tables
1) users - user_id, username, password, email, phone number, role
2) roles - id, name [ie admin, supervisor, ect..]
a) My first doubt is we have any provision to set auto increment for user_id fields ?
b) Is this correct way of setting primary key as user_id?
c) Is this is the correct method to store user role in dynamo db? ie a roles table contains id and title and store role id in user table?
e) Is this possible to retrieve two tables data along with each user? Am using rails 3 and aws-sdk gem
If anybody reply it will be very helpful for me like a new dynamodb user
Typically with nosql style databases you would provide the unique identifier, rather than having an auto increment PK field do that for you. This usually would mean that you would have a GUID be the key for each User record.
As far as the user roles, there are many ways to accomplish this and each has benefits and problems:
One simple way would be to add a "Role" attribute to the Users table and have one entry per role for that user. Then you could grab the User and you would have all the roles in one query. DynamoDB allows attributes to have multiple values, so one attribute can have one value per role.
If you need to be able to query users in a particular role (ie. "Give me all the Users who are Supervisors") then you will be doing a table scan in DynamoDB, which can be an expensive operation. But, if your number of users is reasonably small, and if the need to do this kind of lookup is infrequent, this still may be acceptable for your application.
If you really need to do this expensive type of lookup often, then you will need to create a new table something like "RolesWithUsers" having one record per Role, with the userIds of the users in the role record. For most applications I'd advise against doing something like this, because now you have two tables representing one fact: what role does a particular user have. So, delete or update needs to be done in two places each time. Not impossible to do, but it takes more vigilance and testing to be sure your application doesn't get wrong data. The other disadvantage of this approach is that you need two queries to get the information, which may be more expensive than the table scan, again, depending on the quantity of records.
Another option that makes sense for this specific use case would be to use SimpleDb. It has better querying capability (all attributes are indexed by default) and the single table with roles as multi-valued attribute is going to be a much better solution than DynamoDB in this case.
Hope this helps!
We have a similar situation and we simply use two DBs, a relational and a NoSQL (Dynamo). For a "User" object, everything that is tied to other things, such as roles, projects, skills, etc, that goes in relational, and everything about the user (attributes, etc) goes in Dynamo. If we need to add new attributes to the user, that is fine, since NoSQL doesn't care about those attributes. The rule of thumb is if we only need something on that object page (that is, we don't need to associate with other objects), then we put in Dynamo. Otherwise, it goes in relational.
Using a table scan on the NoSQL DB is not really an option after you cross even a small threshold (up to that point, you can just use an in memory DB anyway).

Resources