Using String.matches() as a Query filter in JDO Query yields no results - datanucleus

Using the code below:
Query query = newJdoQuery();
query.setFilter("identifier.matches('partner|account')");
query.execute();
yields no result. Why?
However, replacing the regex part with 'partner'. The query yields 1 result.
Replacing it with 'account' yields another 6 results. Have a look at the image below.

Related

InfluxDB Flux query how to get distinct values from query

I have written the following Flux query in Grafana, I get two results for value. I would like to filter those two by distinct values by scenario key.
I would expect to have "main_flow" and "persons_end_user" results at the end. How can I achive this, I have tried with distinct() and unique(), but does not seem to work.

Exporting result to csv in the middle of a cypher query

I'm trying to export the results of a query to csv and still re-use the values from the query result as inputs for the second stage of the query.
I submit an initial query in my postgres database and pass the results to neo4j using apoc.load.jdbc. I've been trying to export the results for this postgres query using apoc.export.csv.query and then use values from the postgres query as search criteria for my cypher query.
This query works without any attempt to write to csv:
CALL apoc.load.jdbc('postgresql_url', 'SELECT paper_id FROM papers LIMIT 1') YIELD row
MATCH (n:paper)<-[r:REFERENCES]-(m:paper) WHERE n.paper_id = row.paper_id
RETURN n, m
Ideally, I'd like a query that does something likes this:
CALL apoc.load.jdbc('postgresql_url', 'SELECT paper_id FROM papers LIMIT 1') YIELD row
CALL apoc.export.csv.query('row', 'export/degree0.csv', {}) YIELD row
MATCH (n:paper)<-[r:REFERENCES]-(m:paper) WHERE n.paper_id = row.paper_id
RETURN n, m
This query returns and error that it row.paper_id is not defined.
I'm trying to get the results of the postgres query written to a csv and use data from that query result in the cypher query.
it is possible you are overriding the row variable.
you can try removing the 'YIELD row' from the export.csv in the second line.
if it doesn't work I would suggest removing also the match line and just Return *, so you can see exactly what the row variable contains.

What's the difference between following two mongodb queries?

I ran following two queries and they returned different results.
// my query 1
> db.events.count({"startTimeUnix":{$lt:1533268800000},"startTimeUnix":{$gte:1533182400000}})
131
// existing app query 2
> db.events.count({"startTimeUnix":{"$lt":1533268800000,"$gte":1533182400000}})
0
The query 2 is already being used in the batch application but it reported to pulling less records which I confirmed from these queries.
//these counts are confusing
> db.events.count()
2781
> db.events.count({"startTimeUnix":{$lt:1533268800000}})
361
> db.events.count({"startTimeUnix":{$gte:1533182400000}})
2780
Use the second query. You can add explain() to find out the query plans. The first query
db.events.count({"startTimeUnix":{$lt:1533268800000},"startTimeUnix":{$gte:1533182400000}})
is evaluated the same as
db.events.explain().count({"startTimeUnix":{$gte:1533182400000}})
Use the command below to view the query plans.
db.events.explain().count({"startTimeUnix":{$lt:1533268800000},"startTimeUnix":{$gte:1533182400000}})
query 2 is an impicit (and proper) way of building AND condition, query 1 is incorrect in terms of MongoDB syntax. The way it gets analyzed is pretty simple, MongoDB takes first condtion and then overrides it with second one so it has the same meaning as:
db.events.count({"startTimeUnix":{$gte:1533182400000}})
first condition simply gets ignored and that's why you're getting more results (described here)
The problem is that mongo doesn't parse operators if the are in quotes.
db.events.count({"startTimeUnix":{"$lt":1533268800000,"$gte":1533182400000}})
means that it looks for the entries where startTimeUnix is an object and contains fields "$lt" and "$gte"
If you'll the next command, this query starts returning 1:
db.events.insert({"startTimeUnix":{"$lt":1533268800000,"$gte":1533182400000}})

Mongo Get Count While Returning Whole Documents and Should Queries

I am new to Mongo and can't seem to figure out the following after reading posts and the documentation. I am executing the following query:
db.collection.find({'name':'example name'})
Which returns 14 results. I can get the count of correctly by executing:
db.collection.find({'name':'example name'}).count()
However, I want to return the full documents and the count in a single query, similar to the way Elasticsearch does. Is there anyway to do this.
Additionally, is there any equivalence to Elasticsearch's Bool should query (http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html). Essentially I would want to rank the results, so that those with attribute 'onSale=True' are returned before 'onSale=False'.
I'm not sure about your second question, whether MongoDB provides some mechanism equivalent to Elasticsearch's Bool should query.
But for your 1st question, I think you can use Cursor.
var cursor = db.collection.find({'name':'example name'});
Once you've got the cursor, you can use it for getting the count in the following way:
cursor.count()
as well as for getting the documents wrapped in an array in the following way:
cursor.toArray()
For more info on cursor, please see the below mentioned link:
http://docs.mongodb.org/manual/tutorial/iterate-a-cursor/

Use distinct and skip in a query

I tried running this:
db.col.find().skip(5).distinct("field1")
But it throws an error.
How to use them together?
I can use aggregation but results are different:
db.col.aggregate([{$group:{_id:'$field1'}}, {$skip:3},{$sort:{"field1":1}}])
What I want is links in sorted order i.e numbers should come first then capital letters and then small letters.
Distinct method must be run on COLLECTION not on cursor and returns an array. Read this
http://docs.mongodb.org/manual/reference/method/db.collection.distinct/
So you can't use skip after distinct.
May be you should use this query
db.col.aggregate([{$group:{_id:'$field1'}}, {$skip:3},{$sort:{"_id":1}}]) because field field1 will not exists in result after first clause of grouping.
Also I think you should do sort at first and then skip because in your query you skip 3 unsorted results and then sort them.
(If you provide more information about structure of your documents and what output you want it would be more clearly and I will correct answer properly)