var ref = db.ref("main")
var usersRef = ref.child("users");
var accountIdVal = 56473;
What datatype is the equalTo query commmand using when I try to search with a variable, like below it does not return the desired result.
usersRef.orderByChild("accountID").equalTo(accountIdVal).once("value",function(snapshot){
//returns all the values in users
});
when the same thing is tried with non referenced value like below it works fine
usersRef.orderByChild("accountID").equalTo(56473).once("value",function(snapshot){
//returns the exact user
});
even when I use accountIdVal.toString() it does not seem to work, am I missing something here?
Hi thanks for the help I figured out the answer it was because I was getting the value of the variable as a Long, it was checking for a Integer and not a string so the datatypes were not matching up.
Related
I can't seem to get this to work with a string
binance.prices(function(ticker) {
console.log("prices()", ticker);
console.log("Price of BNB: ", ticker.BNBBTC);
});
returns the correct value, however,
binance.prices(function(ticker) {
var tickerName = "BNBBTC";
console.log("prices()", ticker);
console.log("Price of BNB: ", ticker.tickerName);
});
returns undefined. I've asked around and haven't been able to get any help on this.
Solved my problem by using ticker[tickerName] instead! Thanks for the help :)
Of course you cannot change it like that.
They are 2 different things
1) var tickerName = "BNBBTC";
this means your variable tickerName value is a string and equal to "BNBBTC"
so ticker.tickerName will not be equal to ticker.BNBBTC (I will explain below)
That is why it return undefined because Node trying to find ticker.tickerName, which means Node trying to find the tickerName attribute from ticker. And your tickerName that you define is a variable, not an attribute of ticker
2) ticker.BNBBTC is a variable that already have a value. Remember, the part of BNBBTC is not a value, nor a string. but it is a attribute of ticker.
Look at the difference, one of them is string, one of them is an attribute to ticker.
if you want to do something like that, maybe you can approach it by using:
binance.prices(function(ticker) {
var tickerName = ticker.BNBBTC;
console.log("prices()", ticker);
console.log("Price of BNB: ", tickerName);
});
Happy Coding!
Addtional:
if you insist want to use ticker.tickerName, you can use this code:
binance.prices(function(ticker) {
var ticker.tickerName = ticker.BNBBTC; #I change this part
console.log("prices()", ticker);
console.log("Price of BNB: ", ticker.tickerName); #I change this part
});
Is it possible to use the aql string handler in ArangoDB to perform a dynamic query? I've tried a number of different ways but it always errors out. For example, I'd like to do something like this:
let sortExpression = sortByDate ? 'SORT ${date}' : `SORT ${name}`
const result = db._query(aql`
FOR doc IN tickets
${sortExpression}
RETURN doc
`)
This example is very simplified, but I have a more complex situation where something like this would be really handy. Is there a way to make something like this work?
If the query was more complex, and I had real variables to embed, I'd write this like the following:
let sortProp = sortByDate ? 'date' : 'name';
var query = aql`
FOR doc IN tickets
SORT #SORT_PROP#
RETURN doc`;
query.query = query.query.replace('#SORT_PROP#', sortProp);
var result = db._query(query);
Maybe this works for your use case, too.
After looking more closely at how the aql string handler works, it turns out what I'm trying to do is just not feasible with it. So I decided to use the regular bind var syntax:
let sortExpression = 'SORT #sortField'
const result = db._query(`
FOR doc IN ##coll
${sortExpression}
RETURN doc
`, {
'#coll': module.context.collectionName('tickets'),
'sortField': sortByDate ? 'date' : 'name'
})
Again this is overkill for the simple example above, but my real world query is much more complex.
I have the following query:
SELECT * FROM c
WHERE c.DateTime >= "2017-03-20T10:07:17.9894476+01:00" AND c.DateTime <= "2017-03-22T10:07:17.9904464+01:00"
ORDER BY c.DateTime DESC
So as you can see I have a WHERE condition for a property with the type DateTimeand I want to sort my result by the same one.
The query ends with the following error:
Order-by item requires a range index to be defined on the corresponding index path.
I have absolutely no idea what this error message is about :(
Has anybody any idea?
You can also do one thing that don't require indexing explicitly. Azure documentBD is providing indexing on numbers field by default so you can store the date in long format. Because you are already converting date to string, you can also convert date to long an store, then you can implement range query.
I think I found a possible solution, thanks for pointing out the issue with the index.
As stated in the following article https://learn.microsoft.com/en-us/azure/documentdb/documentdb-working-with-dates#indexing-datetimes-for-range-queries I changed the index for the datatype string to RangeIndex, to allow range queries:
DocumentCollection collection = new DocumentCollection { Id = "orders" };
collection.IndexingPolicy = new IndexingPolicy(new RangeIndex(DataType.String) { Precision = -1 });
await client.CreateDocumentCollectionAsync("/dbs/orderdb", collection);
And it seems to work! If there are any undesired side effects I will let you know.
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.
Ok this seems so silly but I'm having some trouble getting this to work. I want to do an #DbColumn() or #DbLookup() to another database. Same server - BUT it's in a folder. And I can't get a result. The view of the database in question is sorted by the first column.
I'm trying to populate choices of a combobox.
I've tried that built in #DbColumn():
var dbname = new Array("", "myfolder\\myDB.nsf");
return #DbColumn(dbname, "byCode", 0)
I've tried that with and without the "double slashes" and with column 0 and also column 1.
I've also tried the XSnippet :
http://openntf.org/XSnippets.nsf/snippet.xsp?id=dblookup-dbcolumn-with-cache-sort-and-unique
That would be my preferred method really because of caching. I tried creating a SSJS function:
function getFacilityList() {
var dbPath = database.getFilePath().split(database.getFileName())[0];
return DbColumnArray("","myfolder\\myDB.nsf","cache", "sort", "byCode", 0)
}
Which I think should have worked but did not.
Any thoughts would be appreciated! Thanks
Try:
var dbname = session.getServerName() + "!!" + "myfolder\\myDB.nsf";
return #DbColumn(dbname, "byCode", 0)