How to model Not In query in Couch DB [duplicate] - dictionary

Folks, I was wondering what is the best way to model document and/or map functions that allows me "Not Equals" queries.
For example, my documents are:
1. { name : 'George' }
2. { name : 'Carlin' }
I want to trigger a query that returns every documents where name not equals 'John'.
Note: I don't have all possible names before hand. So the parameters in query can be any random text like 'John' in my example.

In short: there is no easy solution.
You have four options:
sending a multi range query
filter the view response with a server-side list function
using a CouchDB plugin
use the mango query language
sending a multi range query
You can request the view with two ranges defined by startkey and endkey. You have to choose the range so, that the key John is not requested.
Unfortunately you have to find the commit request that somewhere exists and compile your CouchDB with it. Its not included in the official source.
filter the view response with a server-side list function
Its not recommended but you can use a list function and ignore the row with the key John in your response. Its like you will do it with a JavaScript array.
using a CouchDB plugin
Create an additional index with e.g. couchdb-lucene. The lucene server has such query capabilities.
use the "mango" query language
Its included in the CouchDB 2.0 developer preview. Not ready for production but will be definitely included in the stable release.

Related

CosmosDB create compound unique index error

I wanted to create a compound unique index using 2 fields, but one of those has a path to some inner field like evaluated.rut. But I got an error:
I don't get the error, in MongoDB I had created index like that, but I can't now in CosmosDB, any suggestion?
Provided the nested path is not an array, the support for this is coming out very soon using the value EnableUniqueCompoundNestedDocs in the capabilities property array for a Cosmos DB databaseAccounts resource in ARM.
This is not yet publicly available. If you'd like to try today you can open a support ticket and ask this capability be added your Cosmos account. You can also DM me on Twitter (see my SO profile) and send me your Cosmos account name and I can request it for you.
You can refer to this document for what is not supported and its limitations.

Querying details from GraphDB

We are trying to implement Customer oriented details in Graphdb, were with a single query we can fetch the details of a customer such as his address,phone,email etc. We have build it using had address, has email edges..
g.addV('member').property('id','CU10611972').property('CustomerId', 'CU10611972').property('TIN', 'xxxx').property('EntityType', 'Person').property('pk', 'pk')
g.addV('email').property('id','CU10611972E').property('pk', 'pk')
g.addV('primary').property('id','CU10611972EP').property('EmailPreference','Primary').property('EmailType', 'Home').property('EmailAddress', 'SNEHA#GMAIL.COM').property('pk', 'pk')
g.V('CU10611972').addE('has Email').to(g.V('CU10611972E'))
g.V('CU10611972E').addE('has Primary Email').to(g.V('CU10611972EP')
This is how we have build email relation to the customer.. Similarly we have relations with Address and Phone. So right now we are using this command to fetch the json related to this customer for email,
g.V('CU10611972').out('has Email').out('has Primary Email')
And for complete Customer details we are using union for each Vertex, Phone,Emaiul and address..
Could you please suggest if there is an efficient way to query this detail?
This comes down really to two things.
General graph data modelling
Things the graph DB you are using does and does not support.
With Gremlin there are a few ways to model this data for a single vertex.
If the database supports it, have a list of names like ['home','mobile'] and use metaproperties to attach a phone number to each.
A lot of the Gremlin implementations I am aware of have chosen not to support meta properties. In these cases you have a couple of options.
(a) Have a property for 'Home' and another for 'Mobile'. If either is not known you could either not create that property or give it a value such as "unknown"
(b) Use prefixed strings such as ["Home:123456789","Mobile:123456789] and store them in a set or list (multi properties) and access them in Gremlin using the startingWith predicate. Such as g.V(id).properties('phone').hasValue(startingWith('Mobile')).value()

How to get column wise data using AEM query SQL2?

I am running a following AEM Query SQL2 on CRXDE and it is successfully returning me nodes as per following given screenshot.
But I need data like column wise (jcr properties) like SQL table. Can anyone help me if it is possible.
You can't do this with CRXDE. It shows only the path of the most outer node, even if the query has multiple columns. This is especially limiting, if your query uses joins.
In your case I would recommend the Query Builder. It has a totally different syntax, but the JSON or XML result contains all data you need.
I don't know other tools. As AEM developer I usually write a quick & dirty servlet, and let it run on my local instance (with production content)
Query Builder Debugger
http://localhost:4502/libs/cq/search/content/querydebug.html
Example Query
path=/content/we-retail/language-masters/en/experience
property=sling:resourceType
property.value=weretail/components/content/image
p.hits=full
p.nodedepth=2
Resulting JSON Query
http://localhost:4502/bin/querybuilder.json?p.hits=full&p.nodedepth=2&path=%2fcontent%2fwe-retail%2flanguage-masters%2fen%2fexperience&property=sling%3aresourceType&property.value=weretail%2fcomponents%2fcontent%2fimage
http://localhost:4502/bin/querybuilder.json?p.hits=full&p.nodedepth=2&path=%2fcontent%2fwe-retail%2flanguage-masters%2fen%2fexperience&property=sling%3aresourceType&property.value=weretail%2fcomponents%2fcontent%2fimage
Documentation
https://docs.adobe.com/content/help/en/experience-manager-64/developing/platform/query-builder/querybuilder-api.html
In your case especially see: Refining What Is Returned
You will find much more with Google, as the Query Builder is pretty old in AEM/CQ.

Why does DynamoDB require expressionAttributeValue?

I'm learning about how to filter results from a scan or query using Amazon's DynamoDB. I would expect an example filter to look like filter => name = Bob or some such. However, Amazon requires the use of a expression attribute such as filter => name = :person and then ExpressionAttributeValues => { ":person": {"S": "Bob"}}
This is confusing and hurts my head, why can't I use the simple name = Bob?
Official docs: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html#FilteringResults
Apparently working example near end: https://github.com/aws/aws-cli/issues/1073
This type of syntax follows an approach that is similar to prepared statements that are used in SQL systems. This was a design decision that the DynamoDB team at AWS made. One of the reasons is to allow fields that conflict with the lengthy list of reserved words (including 'name' that you were using in your example) that are defined by DynamoDB.
Avoiding reserved words is actually performed by using the ExpressionAttributeNames attribute and specifying the attribute names. You were referencing ExpressionAttributeValues which is where the list of values is specified. More information is available on the Using Placeholders for Attribute Names and Values documentation page.
Another motivation of this design is to separate the statement from the parameter names and values, similar to prepared statements in SQL as I've already mentioned. While this may seem odd at first it has the added benefit of effectively sanitizing your inputs in a NoSQL sense avoiding possible malicious or unintentional problems with your user input affecting the behavior of your request on the interaction with DynamoDB.

MVC3 routes - replace id with object name

I'm looking for a fast & elegant way of converting my object IDs with descriptive names, so that my autogenerated routes look like:
/products/oak-table-25x25-3-1
instead of
/products/5bd8c59c-fc37-40c3-bf79-dd30e79b55a5
In this sample:
uid = "5bd8c59c-fc37-40c3-bf79-dd30e79b55a5"
name = "Oak table (25x25) 3/1"
I don't even know how that feature could be named, so that I might google for it.
The problem that I see so far is the uniqueness of that "url-object-name", for example if I have two oak tables 25x35 in the db, and their names differ too little to be uniquely url-named but enough to fool the unique constraint in the db.
I'm thinking of writing that function for name-transform in SQL as an UDF, then adding a calculated field that returns it, then unique-constraining that field.
Is there some more mainstream way of achieving that?
One method is that employed by stackoverflow.com which in your case would be:
/products/5bd8c59c-fc37-40c3-bf79-dd30e79b55a5/oak-table-25x25-3-1
This ensures uniqueness, however the length of the UUID may be a deterrent. You may consider adding a sequential int or bigint identity value to the products table in addition to the uniqueidentifier field. This however would require an additional index on that column for lookup, though a similar index would be required for a Url having only a descritive string. Yet another method would be to use a hash value, seeded by date for instance, which you can compose with the descriptive name. It is simpler to rely on a sequential ID value generated by a database, but if you envision use NoSQL storage mechanisms in the future you may consider using an externally generated hash value to append.
Identity should have 2 properties: it should be unique and unchangable. If you can guarantee, that /products/oak-table-25x25-3-1 will never change to /products/oak-table-25x25-3-1-1 (remember, user can have bookmarks, that shouldn't return 404 statuscode)- you can use name as url parameter and get record by this parameter.
If you can't guarantee uniqueness or want to select record more faster - use next:
/products/123/oak-table-25x25-3-1 - get record by id (123)
/products/123/blablabla - should redirect to first, because blabla no exists or have anoher id
/products/123 - should redirect to first
And try to use more short identities - remember, that at web 2.0 url is a part of UI, and UI should be friendly.
MVC routing (actions) will handle spaces and slashes in a name. It will encode them as %20, and then decode them correctly.
Thus your URL would be /products/oak%20table%2025x25-3%2F1
I have done something very similar in an eCommerce platform I am working on.
The idea is that the URL without the unique ID is better for SEO but we didn't want the unique ID to be the product name that can change often.
The solution was to implement .NET MVC "URL slug only" functionality. The product manager creates "slugs" for every product that are unique and are assigned to products. These link to the product but the product ID and name can be changed whenever.
This allows:
domain.com/oak-table-25x25-3-1
to point to:
/products/5bd8c59c-fc37-40c3-bf79-dd30e79b55a5
(The same functionality can be used on categories too so domain.com/tables can point to domain.com/category/5b38c79c-f837-42c3-bh79-dd405479b15b5)
I have documented how I did this at:
http://makit.net/post/3380143142/dotnet-slug-only-urls

Resources