Marklogic 8 nodejs queryBuilder.orderBy SEARCH-BADORDERBY - node.js

I get this
SEARCH-BADORDERBY: (err:FOER0000) Indexes are required to support element, element-attribute, json-property, or field sort specifications
everytime i try to use the orderBy. I tried in all possible ways.
qb.where(qb.value("hasGeolocation", true)).orderBy("username")
or
qb.where(qb.value("hasGeolocation", true)).orderBy(qb.property("username"))
or
qb.where(qb.value("hasGeolocation", true)).orderBy(qb.sort("username"))
or
qb.where(qb.value("hasGeolocation", true)).orderBy(qb.sort(qb.property("username")))
and for the sort i tried with 'ascending' or 'descending' direction. Nothing works. Am I doing something wrong or is there something wrong with the MarkLogic Node Api?

Victor, it looks to me like you haven't defined a range index on "username". Define a string range index on "username" and I think you'll be set.

Related

nodejs bigquery parameterised query inside IN() expression

I am trying to run a parameterised query using the npm module #google-cloud/bigquery.
Something like this:
SELECT * FROM myTable WHERE id IN (#ids);
I have no idea how bigQuery is expecting the parameter ids formatted.
My options.params look like something like this:
{ ids: '"1234", "4567"'}
But I don't get any result back. I know there are results, I can see them in bigquery and if I remove the parameter and just inject the string works just fine.
It seem pretty easy, but I can't figure out why it doesn't work, anyone who is willing to help me out?
Thank you in advance
Of course I found the solution as soon as I posted the question...
Thanks to this thread! Need to do some gymnastic...
So provided that the parameter is a string like:
'1234,5678'
We need to do:
WHERE id IN UNNEST(REGEXP_EXTRACT_ALL(#ids,"[0-9a-zA-Z]+"))
REGEXP_EXTRACT_ALL - returns an array
UNNEST - flattens the array for the IN clause as stated in the link above.

Loopback 4 compound query string syntax

I am trying to put together a compound json query string using the where filter to access my loopback API. Simple or statements work when they are the only items in the query string.
https://loopback.io/doc/en/lb4/Parsing-requests.html
As an example the following query string will return the two correct ids:
http://xxx.xxx.xxx/api/products?filter={"where":{"or":[{"ProductId": "AOC"},{"ProductId": "BCK"}]}}
But when I try to make it more complex such as trying to filter for all "flower" products that have a strain type of "I" or "H", I get a 400 error:
http://xxx.xxx.xxx/api/products?filter=filter={"where":{"and":[{"ProductType": "flower"},{"or":[{"ProductStrain": "H"},{"ProductStrain": "I"}]}]}}
Same with:
http://xxx.xxx.xxx/api/products?filter=filter={"where": {"ProductType": "flower"},{"or":[{"ProductStrain": "I"},{"ProductStrain": "H"}]}}
I am guessing that I have a syntax issue, but I have tried a dozen different ways and still haven't got what I want. Can someone point me in the right direction?

Unable to query using only the rangeKey

I just started working on DynamoDB so please forgive me if the following seems like a dumb mistake.
I have a model with a hashKey and a rangeKey. Let's name these as HASH and RANGE respectively.
A global secondary index: GlobalIndex is added to the model as well.
Now what I want is to get the list of records by rangeKey. I don't want to use the scan operation since it impacts the performance. I am unable to achieve this with the query operation.
Trying to achieve something like this with dynogels.
Any kind of help would be really helpful.
Thanks.
Dynogels: 9.0.0
Node: 6.10.3
It was a mistake on my end. The index has the same hash key and range key as the table.
The GitHub issue thread for the same: https://github.com/clarkie/dynogels/issues/137

mongo: "2d" index and normal index

location: {lat: Number,
lng: Number}
location is a 2d index in my mongodb and I have been using this for geospatial search, which is working fine.
Now if I need to search as db.find({lat:12.121212, lng:70.707070}), will it use the same index ? or, do I need to define a new index ? If so, how ?
I am using mongoose driver in node.js
The 2d index used for doing the geospatial commands is not going to help for an equivalency match on the two fields. For that you will need to define a compound index on the two sub-documents, something like this:
db.collection.ensureIndex({"location.lat" : 1, "location.lng" : 1})
This worked best for me with a test set of data - you can also define a normal index on the location field itself but that will be less efficient. You can test out the relative performance using hint and explain for any index combination. For example:
db.collection.find({"location.lat" : 179.45, "location.lng" : 90.23}).hint("location.lat_1_location.lng_1").explain()
You can do this for any index you wish in fact, though to check the results returned you will need to drop the .explain()
Please also bear in mind that a query can only use one index at a time, so if you are looking to combine the two (equivalency and a geospatial search) then the 2d index will be the only one used.
Note: all of the above examples are from the MongoDB JS shell, not node.js

search with startkey, endkey and array keys

I have a view wich returns several elements with array keys.
Example :
{"total_rows":4,"offset":0,"rows":[
{"id":"","key":[15,"2"],"value":1,"doc":{},
{"id":"","key":[20,"2"],"value":1,"doc":{},
{"id":"","key":[20,"3"],"value":1,"doc":{},
{"id":"","key":[20,"4"],"value":1,"doc":{}
]}
I'm trying to search through those elements. So if I do the following request :
/database/_design/element/_view/all/?
startkey=[15, "2"]&
endkey=[20, "3"]&
include_docs=true&reduce=false
Live example : http://jchris.couchone.com/keyhuh/_design/Record/_view/by_CreationDate_and_BoreholeName?startkey=[1267686720,%22sp4%22]&endkey=[1267686725,%22sp4\u9999%22]&include_docs=true&reduce=false
This one doesn't works. It returns me all the records, even the last one, which doesn't meets the second element of the array.
Strangely enough, it works with strings only.
Example :
{"total_rows":4,"offset":0,"rows":[
{"id":"","key":["15","2"],"value":1,"doc":{},
{"id":"","key":["20","2"],"value":1,"doc":{},
{"id":"","key":["20","3"],"value":1,"doc":{},
{"id":"","key":["20","4"],"value":1,"doc":{}
]}
if I do the following request :
/database/_design/element/_view/all/?
startkey=["15", "2"]&
endkey=["20", "3"]&
include_docs=true&
reduce=false
Live Example : http://jchris.couchone.com/keyhuh/_design/Record/_view/by_Client_and_BoreholeName?startkey=[%22Test1%22,%22sp4%22]&endkey=[%22Test1%22,%22sp4\u9999%22]&include_docs=true&reduce=false
Here it'll work well and only return the three first elements.
Am I missing something with couchdb's search for arrays with integers and strings ? Or have I fallen on a bug ?
Note : it does the same with CouchDB 0.10 and 0.11.
This looks wrong, and there are a few things it could be. Is it possible for you to share your code with us? If the data isn't proprietary you could replicate your db to http://jchris.couchone.com/keyhuh and I'll take a look at the whole thing there.
...
Thanks for posting the live data. This is the query that is busted?
http://jchris.couchone.com/keyhuh/_design/Record/_view/by_Client_and_BoreholeName?startkey=[%22Test1%22,%22sp4%22]&endkey=[%22Test1%22,%22sp4\u9999%22]&reduce=false
Because that looks fine to me. What am I missing?

Resources