How to add allowDiskUse to mongooperation.find method in spring boot - mongodb-query

The below query i want to add allowDiskUse true. I am able to add allowDiskUsage to aggregation query but not able to find a solution for find method
Query query = new Query().with(pageable).addCriteria(criteria).collation(collation);
mongoOperations.find(query, RuntimeApplication.class, RUNTIME_APP);
I want to know is that possible to add allowDiskUsage to find method or i need to change query to aggregation.
i just found in below query from internet. but i am not getting how to convert it into spring boot
db.collection.find(<match>).sort(<sort>).allowDiskUse()

What kind of spring-data version are you using? You should be able to add allowDiskUse to the Query object just like this:
val query = Query()
.with(Pageable.ofSize(1))
.addCriteria(Criteria())
.allowDiskUse(true)
And then afterwards use the query with find for instance with mongoTemplate.
Here is the documentation: https://javadoc.io/doc/org.springframework.data/spring-data-mongodb/latest/org/springframework/data/mongodb/core/query/Query.html

Related

Is there a way to execute text gremlin query with PartitionStrategy

I'm looking for an implementation to run text query ex: "g.V().limit(1).toList()" while using the PatitionStrategy in Apache TinkerPop.
I'm attempting to build a REST interface to run queries on selected graph paritions only. I know how to run a raw query using Client, but I'm looking for an implementation where I can create a multi-tenant graph (https://tinkerpop.apache.org/docs/current/reference/#partitionstrategy) and query only selected tenants using raw text query instead of a GLV. Im able to query only selected partitions using pythongremlin, but there is no reference implementation I could find to run a text query on a tenant.
Here is tenant query implementation
connection = DriverRemoteConnection('ws://megamind-ws:8182/gremlin', 'g')
g = traversal().withRemote(connection)
partition = PartitionStrategy(partition_key="partition_key",
write_partition="tenant_a",
read_partitions=["tenant_a"])
partitioned_g = g.withStrategies(partition)
x = partitioned_g.V.limit(1).next() <---- query on partition only
Here is how I execute raw query on entire graph, but Im looking for implementation to run text based queries on only selected partitions.
from gremlin_python.driver import client
client = client.Client('ws://megamind-ws:8182/gremlin', 'g')
results = client.submitAsync("g.V().limit(1).toList()").result().one() <-- runs on entire graph.
print(results)
client.close()
Any suggestions appreciated? TIA
It depends on how the backend store handles text mode queries, but for the query itself, essentially you just need to use the Groovy/Java style formulation. This will work with GremlinServer and Amazon Neptune. For other backends you will need to make sure that this syntax is supported. So from Python you would use something like:
client.submit('
g.withStrategies(new PartitionStrategy(partitionKey: "_partition",
writePartition: "b",
readPartitions: ["b"])).V().count()')

How to locate the node in JCR using uuid from query

This is the error I get.
16.03.2016 12:02:16.413 WARN [xxx.xxx.xx.xxx [1458147736268] GET /en/employees-leaders/employee-s-toolkit2/epd-update/epd-update-archives/caterpillar-news/upcoming-brand-webinarfocusonmarketing.html HTTP/1.1] com.day.cq.wcm.core.impl.LanguageManagerImpl Error while
retrieving language property. javax.jcr.AccessDeniedException: cannot
read item xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (alpha-numeric)
I am trying to locate the node in JCR using the xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, which I believe is uuid, using a query in AEM.
Is the xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx actually a uuid?
How do I locate the source i.e node, causing the issue?
I tried running a sql with the above id in the jcr, but it returned no result.
//*[jcr:contains(., '91186155-45ad-474-9ad9-d5156a398629')] order by #jcr:score descending
Any other insights would be much appreciated.
You don't need a query if you know the Node's UUID, just use the Session.getNodeByIdentifier(String id) method.
Your query is not SQL as you stated, it's XPATH. Is that a typo or did you run the query incorrectly?
It certainly looks like a UUID. You can query for the jcr:uuid property or you can continue doing a full text search.
XPATH:
/jcr:root//*[jcr:contains(., '91186155-45ad-474-9ad9-d5156a398629')]
/jcr:root//*[#jcr:uuid='91186155-45ad-474-9ad9-d5156a398629']
JCR-SQL2:
SELECT * FROM [nt:base] AS s WHERE contains(s.*, '91186155-45ad-474-9ad9-d5156a398629')
SELECT * FROM [nt:base] WHERE [jcr:uuid] = '91186155-45ad-474-9ad9-d5156a398629'
What read permissions does your account have? You're going to find a lot of results for a jcr:uuid query will be under /jcr:system/jcr:versionStorage.
Use QueryBuilderDebugger, (localhost:4502/libs/cq/search/content/querydebug.html) and run similar query as below to get the node for a given uuid:
property=jcr:uuid
property.value=e69b256e-a466-3730-866b-de22c82ab8ck
path=/home
type=rep:Group
p.limit=10

Endeca UrlENEQuery java API search

I'm currently trying to create an Endeca query using the Java API for a URLENEQuery. The current query is:
collection()/record[CONTACT_ID = "xxxxx" and SALES_OFFICE = "yyyy"]
I need it to be:
collection()/record[(CONTACT_ID = "xxxxx" or CONTACT_ID = "zzzzz") and
SALES_OFFICE = "yyyy"]
Currently this is being done with an ERecSearchList with CONTACT_ID and the string I'm trying to match in an ERecSearch object, but I'm having difficulty figuring out how to get the UrlENEQuery to generate the or in the correct fashion as I have above. Does anyone know how I can do this?
One of us is confused on multiple levels:
Let me try to explain why I am confused:
If Contact_ID and Sales_Office are different dimensions, where Contact_ID is a multi-or dimension, then you don't need to use EQL (the xpath like language) to do anything. Just select the appropriate dimension values and your navigation state will reflect the query you are trying to build with XPATH. IE CONTACT_IDs "ORed together" with SALES_OFFICE "ANDed".
If you do have to use EQL, then the only way to modify it (provided that you have to modify it from the returned results) is via string manipulation.
ERecSearchList gives you ability to use "Search Within" functionality which functions completely different from the EQL filtering, though you can achieve similar results by using tricks like searching only specified field (which would be separate from the generic search interface") I am still not sure what's the connection between ERecSearchList and the EQL expression above?
Having expressed my confusion, I think what you need to do is to use String manipulation to dynamically build the EQL expression and add it to the Query.
A code example of what you are doing would be extremely helpful as well.

How to use query.filter and .filter_by in SQLAlchemy?

With Django it is possible to find models using the filter method with keyword-arguments like so:
MyModel.objects.filter(serialNo_gt=10)
giving all models with a serial number greater than 10.
Is it possibly to use a similar query language with sql-alchemy? I know that one can write something like MyModel.seriealNO < 10, but with that the code that uses this construct need to import MyModel and I want to create the keywords/query parameters externally without importing MyModel (for a facade-pattern).
the concept of "<attributename>_<operatorname>=<value>" is not built in to SQLAlchemy's Query, however the effect is very easy to reproduce. Here's a quick example done by the author of Flask: https://github.com/mitsuhiko/sqlalchemy-django-query/blob/master/sqlalchemy_django_query.py

From within a grails HQL, how would I use a (non-aggregate) Oracle function?

If I were retrieving the data I wanted from a plain sql query, the following would suffice:
select * from stvterm where stvterm_code > TT_STUDENT.STU_GENERAL.F_Get_Current_term()
I have a grails domain set up correctly for this table, and I can run the following code successfully:
def a = SaturnStvterm.findAll("from SaturnStvterm as s where id > 201797") as JSON
a.render(response)
return false
In other words, I can hardcode in the results from the Oracle function and have the HQL run correctly, but it chokes any way that I can figure to try it with the function. I have read through some of the documentation on Hibernate about using procs and functions, but I'm having trouble making much sense of it. Can anyone give me a hint as to the proper way to handle this?
Also, since I think it is probably relevant, there aren't any synonyms in place that would allow the function to be called without qualifying it as schema.package.function(). I'm sure that'll make things more difficult. This is all for Grails 1.3.7, though I could use a later version if needed.
To call a function in HQL, the SQL dialect must be aware of it. You can add your function at runtime in BootStrap.groovy like this:
import org.hibernate.dialect.function.SQLFunctionTemplate
import org.hibernate.Hibernate
def dialect = applicationContext.sessionFactory.dialect
def getCurrentTerm = new SQLFunctionTemplate(Hibernate.INTEGER, "TT_STUDENT.STU_GENERAL.F_Get_Current_term()")
dialect.registerFunction('F_Get_Current_term', getCurrentTerm)
Once registered, you should be able to call the function in your queries:
def a = SaturnStvterm.findAll("from SaturnStvterm as s where id > TT_STUDENT.STU_GENERAL.F_Get_Current_term()")