How can I retrive an element value from array in gfsh - gfsh

I have the following data in gfsh DB:
gfsh>query --query="select * from /siteinfo"
Result : true
Limit : 100
Rows : 4
Result
----------------------------------------------------------------------------------------------------------
{"id":"9347292b-cad8-4837-92b0-df34b8083901","lastUpdateTime":"1646376430201","fqdn":"test03.east.net","weight":1,"administrativeState":"unlocked","distributedSystemId":"3","lastSeenPeerUpdateTime":["4:1646376427321","1:1646376427321","2:1646376427321","3:1646376427321"],"siteLeader":false}
{"id":"1493a604-1ea2-44fa-9fe4-3cb99ed8d71b","lastUpdateTime":"1646376431751","fqdn":"test01.east.net","weight":1,"administrativeState":"unlocked","distributedSystemId":"1","lastSeenPeerUpdateTime":["2:1646376431235","4:1646376431235","3:1646376431235","1:1646376431235"],"siteLeader":true}
{"id":"73ddaee1-e586-42ce-8a78-c5c3ad324bba","lastUpdateTime":"1646376430995","fqdn":"test02.east.net","weight":1,"administrativeState":"unlocked","distributedSystemId":"2","lastSeenPeerUpdateTime":["2:1646376429276","4:1646376429276","1:1646376429276","3:1646376429276"],"siteLeader":false}
{"id":"150f58b5-e43e-40ef-a25d-2c5f2a69c06b","lastUpdateTime":"1646376430783","fqdn":"test04.east.net","weight":1,"administrativeState":"unlocked","distributedSystemId":"4","lastSeenPeerUpdateTime":["1:test","2:test","3:test","4:test"],"siteLeader":false}
You may see that there is no specific title in the result.(the 'Result' word is returned by gfsh)
gfsh>query --query="select e.value.Result from /siteinfo.entries e"
Result : true
Limit : 100
Rows : 4
Value
---------
UNDEFINED
UNDEFINED
UNDEFINED
UNDEFINED
How can I retrive the 'fqdn' only for 'siteLeader' is 'true'?

I'm not sure what the question is here, because this is directly in the Querying FAQ and Examples: Can I see query string examples, listed by query type? page and not all that much different from regular SQL:
select s.fqdn from /siteinfo s where s.siteLeader = true

Related

How to query field exist some document in firebase

I using firebase, nodejs and i have a question how to query field exist some document.
Example :
Collections : users => document : A with field {
....
is_correct: true
}
document : B with field {
.....
}
In my above example , i have two document in collection users. On document A i have field is_correct: true and on document B field is_correct not exist.
My collection users about 15.000 document and it have 50 document contain field is_correct: true
When i write code look like :
await firestore.collection('users').where('is_correct', '==', true).get();
it can get correct me 50 document. But i don't understand it can using index on field is_correct or not ? And it can query best performance ? I understand firebase can't get document if field undefined. It impart in case ? Please help ? Thanks you
For a simple query like
firestore.collection('users').where('is_correct', '==', true)
you don't need to configure any index, Firestore does it automatically.
As you mentioned, only documents where the given field exists can match the query.
And this is the case also for Not-equal (!=) and not-in queries: they exclude documents where the given field does not exist, as explained in the documentation.
Also, note that a field exists when it's set to any value, including an empty string (""), null, and NaN (not a number).
So, in conclusion, if you want to query for documents where is_correct is not true, you need to create this field in these documents with a value different than true.

How to obtain nested fields within JSON

Background:
I wish to update a nested field within my JSON document. I want to query for all of the "state" that equal "new"
{
"id": "123"
"feedback" : {
"Features" : [
{
"state":"new"
}
]
}
This is what I have tried to do:
Since this is a nested document. My query looks like this:
SELECT * FROM c WHERE c.feedback.Features.state = "new"
However, I keep ending up with zero results when I know that this exists within the database. What am I doing wrong? Maybe I am getting 0 results because the Features is an array?
Any help is appreciated
For arrays, you'll need to use ARRAY_CONTAINS(). For example, in your case:
SELECT *
FROM c
WHERE ARRAY_CONTAINS(c.feedback.Features,{'state': 'new'}, true)
The 3rd parameter specifies that you're searching within documents within the array, not scalar values.

Aggregation with two different conditions

I'v one issue to write aggregation query. I'v 3 doc.I want filter 2 doc with some condition.In which 2 doc having same data with 1 changed value.
I have 3 entries of data in database. English is default lang for my data. In which 2 entries(one with default lang and other with 'Hindi' lang) having same data with some unique id with one diff language parameter and 3rd entry having only data in default lang another uniqueid.
Now I want data in following condition:
1) I have have sent English as a lang parameter Then query will find out the data with english lang
2) If I send Hindi lang as a parameter then from all entries I get 2 entries one entries with hindi lang and one entry with english(default lang) as a result
Query :
certification.find({$and: [{certificate_id: certificate_id}, {$or : [{lang : lang }, {lang : 'English'}]}]});
lang, certificate_id : parameter passed by user
Please help me to write query with mongodb.

TypeError: Cannot read property 'substring' of undefined

Written in node.js file
The function is returning the error:
Returns the ACE occupation exhibit identifier
Example of originalID: 46R-002-30BroadJour12_01-12_11
Expected output: 46R-002
/*This function is returning the error:
Cannot read property 'substring' of undefined*/
function splitID(originalID){
var aceid = originalID.substring(0,7);
return aceid;
}
//1. Get the ace exhibit occupation id for each of them and put it in a parallel array.
for (var row in values) {
//split the 5th column using our function
var output = splitID(row[4]);
var result = getOccupation(output);
//now we add the split output to our occupation array.
occupationsToInsert.append(result);
}
If you may refer to the documentation here at MDN, it advises against using for...in for looping over the arrays because it does not give consistent values on return. It rather iterates on the enumerable properties of the concerned object passed to it.
In other words, for (var row in values) would not iterate over each individual rows as expected, but rather the enumerable properties of the values list.
So, for your const array, you can find the enumerable properties by simply doing
Object.getOwnPropertyNames(values)
which would return you the following list :
["0", "length"]
You're essentially trying to access the fourth element of this array which doesn't exist, and thereby it is undefined, causing the error you observe.
The error is telling you the exact problem: originalID is undefined. In your for loop, row[4] is resulting in an undefined value. Verify your values array contains what you are expecting.

Function for `fq` field of SOLR in SOLR-node-client

For various fields such as q , start , row etc in SOLR we have corresponding functions in SOLR-node-client.
So if I want to construct a query for the following:
http://host:port/solr/eposro/select?q=cats.0%3A1&start=0&rows=4&wt=json&indent=true
I can use something like this:
var query = client.createQuery()
.q({cats.0 : 1})
.start(0)
.rows(4);
However, there is a filter query field in SOLR, fq. I don't seem to find a corresponding function for this in SOLR-node-client.
Following gives me error:
var query = client.createQuery()
.q({cats.0 : 1})
.fq({'brand':'real'})
.start(0)
.rows(4);
I get an error saying that fq function doesn't exist.
Am I doing anything wrong or is there any other way to achieve filter query using SOLR-node-client?
createQuery() returns a Query object and it has a matchFilter method.
Example:
var query = client.createQuery()
.q({cats.0 : 1})
.matchFilter('brand', 'real')
.start(0)
.rows(4);
HTH
I have checked a bit the source code and found out:
So, the usage should be like,
let searchQuery = solrClient.query()
searchQuery = searchQuery.fq({field:"tags",value: this.filterTag});
If anyone can update the doc, that would be great.

Resources