How to get negetive of a complex where clause in mongo db - pymongo

I have a mongo db complex filter generated dynamically which might look like
where_condition = {"$and":[{"column_3": "Offer"}, {"column_2":"MSN"}]}
collection.find(where_condition)
The condition might have unknown depth in $and and $or
Is it possible to find the negative of the where_condition
This does not work
not_condition = {"$not": where_condition}

You'll want to use $nor. Something like this:
where_condition = {"$and":[{"column_3": "Offer"}, {"column_2":"MSN"}]}
not_condition = {"$nor":[{"column_3": "Offer"}, {"column_2":"MSN"}]}
You can find some more info on the mongodb doc for $nor.

Related

Does Mongoengine allow pull from <variable>?

I have a few pull queries that look like this:
Site.objects(siteid).update_one(pull__somelist__refid=myid)
I would like to reuse this code by making 'somelist' a variable - something like this:
listvar = 'somelist'
Site.objects(siteid).update_one(pull__<listvar>__refid=myid)
I have tried various wrappers such as [listvar] and (listvar) without success.
Is there a way to inject the variable value into the query?
You should be able to abuse the kwarg notation for this
myvar = "some_var"
funky_kwarg = {f"pull__{myvar}__refid": myid}
Site.objects(siteid).update_one(**funky_kwarg)

Convert SQL request to Hibernate Criteria

I would like to convert this SQL into either Criteria. I am sorry I don't know which one to use since I'm new to Hibernate. I've done some research, and it looks like both are needed to achieve what I wanted.
My Sql Request
select *
from change.pade pade, change.pade_etat rdp, par.safsit safsit, par.saf saf
where pade.sir = "1245454"
and pade.id_safsit = "1"
and pade.id_safsit = safsit.id
and safsit.cd_s in ("12", "45")
and safsit.fk_saf = saf.id
and saf.cd_ur in "124"
and rdp.fk_pade = pade.id
and rdp.id_etat in "444"
You can use the Hibernate properties instead of writing HQL like this
session.createSQLQuery(String sqlQuery)
see an example here

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.

ReleaseCumulativeFlowData and CardState

I'm trying to run a query against the ReleaseCumulativeFlowData object as follows:
((ReleaseObjectID = 12345) AND CardState="Accepted")
However, running the query results in the following error message:
OperationResultError
Could not read: could not read all instances of class
com.f4tech.slm.domain.reporting.ReleaseCumulativeFlowDataSet
Is this a bug in Rally?
WSAPI is very picky about the structure of the query. You have to include parentheses around chained query filters, so you would need something like the following:
((ReleaseObjectID = 12345) AND (CardState = "Accepted"))

Lucene: Can I run a query against few specific docs of the collection only?

Can I run a query against few specific docs of the collection only ?
Can I filter the built collection according to documents fields content ?
For example I would like to query over documents having field2 = "abc".
thanks
Sure -- use a Filter. See http://lucene.apache.org/java/3_0_1/api/core/org/apache/lucene/search/QueryWrapperFilter.html
The code will look something like:
QueryParser qp = ...
Filter filter = new QueryWrapperFilter(qp.parse("field2:abc"));
// pass filter to searcher.search()