Query numerical string values in Orion Context Broker - fiware

I am failing to query a string property set with a numerical value. Example:
//entity in orion
{
"id": "Test.2",
"type": "Test",
"nombre": "1"
}
//query
http://<some-ip>:<some-port>/v2/entities?type=Test&q=nombre==1
//response
[]
I changed the attribute to store a number and the query works well then. Anyway, it should be possible to query numerical string values, shouldn't it?
EDIT
I found this problem will be issued in version 0.26

As described in the issue cited by #nespapu, NGSIv2 will allow that posibility in the following way:
//query
http://<some-ip>:<some-port>/v2/entities?type=Test&q=nombre=='1'
However, current Orion version at the time of writting this (0.24.0) doesn't implemented yet such functionality.
EDIT: implemented since Orion 1.3.0

Related

Declare array of bsonType in mongoDb schema

How to declare an array of different types in mongoDb schemas?
I have a value in a document which can be a double or an int and I tried declaring it like this:
"numberOf": {
"bsonType": ["long", "int"]
},
And I received that error:
property "numberOf" has invalid type: type [long,int] is not supported
In the doc they say that you can declare an array of bsonTypes or types like that:
"type": "<JSON Type>" | ["<JSON Type>", ...],
"bsonType": "<BSON Type>" | ["<BSON Type>", ...],
I also tried:
"numberOf": {
"type": "number"
},
And I can't save my schema getting this:
I don't know what I missed.
So apparently the problem would come from Sync see here.
They working on it.
Right now, it is not possible to sync multiple types of data for a single field.
What I did is I changed my types to "mixed":
"numberOf": {
"bsonType": "mixed"
},
This feature is in beta (see here) and, probably, you'll have to update your Realm package.
Just do in your terminal
npm install realm
Then
cd ios
pod install
Be careful of breaking changes.
If needed, uninstall your application on your emulator/simulator then
npx react-native run-ios
or
npx react-native run-android

How to create advanced subscriptions expression at Orion Context Broker NGSIv2?

According to official documentation of Orion Context Broker NGSIv2 :
You can include filtering expressions in conditions. For example, to
get notified not only if pressure changes, but if it changes within
the range 700-800. This is an advanced topic, see the "Subscriptions"
section in the NGSIv2 specification.
At NGSIv2 subscriptions there is no notifyConditions such as NGSIv1 , it was replaced by subject.condition object:
condition: Condition to trigger notifications. This field is optional
and it may contain two properties, both optional:
attrs: array of attribute names
expression: an expression composed of q, mq, georel,
geometry and coords (see "List entities" operation above about this
field)
When we use subject.condition.attrs, it contains an array of attributes names, these names define the "triggering attributes", i.e. attributes that upon creation/change due to entity creation or update trigger the notification.
But, for subject.condition.expression there is not example at official documentations.
Getting pieces of puzzle is possible to deduce :
Is possible do combine subject.condition.expression and subject.condition.attrs. If I set and attribute different of expression,eg. attr foo with expression 'boo>10' what it will do ? Will this behave like an OR or AND ?
Is possible to set multiple expressions. Will this behave like an OR or AND ?
It would be nice to have some examples of these more complex subscriptions combining the different ways of delimiting the entities in the subscription.
NOTE: This question is related to Orion Version 1.7.0+
I think the following example, from the NGSIv2 Overview for Developers That Already Know NGSIv1 presentation (slide 34 in the current version), could help to clarify.
Example: subscribe to speed changes in any entities of any type ending with Vehicle (such as RoadVehicle, AirVehicle, etc.) whenever speed is greater than 90 its average metadata is between 80 and 90 and the vehicle distance to Madrid city center is less than 100 km
Request:
POST /v2/subscriptions
...
{
"subject": {
"entities": [
{
"idPattern": ".*",
"typePattern": ".*Vehicle"
},
],
"condition": {
"attrs": [ "speed" ],
"expression": {
"q": "speed>90",
"mq": "speed.average==80..100",
"georel": "near;maxDistance:100000",
"geometry": "point",
"coords": "40.418889,-3.691944"
}
}
},
...
}
As this example illustrates, you can use different conditions (q, mq, geoquery, etc.) and they are interpreted in the AND sense. Morevoer, q and mq allow complex expressions interpreted also in the AND sense, such as:
"q": "speed>90;engine!=fail",
Note that q and mq when they appear in subscriptions expression follow the same rules than the ones when they appear in synchronous queries (i.e. GET /v2/entities?q=...). These rules are described in "Simple Query Language" section in the NGSIv2 specification.

compare multiple JSON keys against same value in dust templates

I have a JSON being passed to a Dust template and want to compare multiple keys for the same value. For example I have a JSON like:
"data": {
"abc": "true",
"xyz": "true",
"uno": "true"
}
Is there a way apart from using "IF" condition(it's deprecated), to compare all of them at once?
I don't wanna do
{?data.abc}
{?data.xyz}
{?data.uno}
<DO something when all of them are true>
{/data.uno}
{/data.xyz}
{/data.abc}
Is there a better way to do the above conditions?
P.S. for dust-helper version 1.5.0 or lower.
After talking to a few developers and researching a lot, there are no specific dustjs filters designed for such a use case for dust-helper version 1.5.0 or lower.
Having said that, the following code seems to work pretty well,
{#select key=abc}
{#eq value="true"/}
{#eq key=xyz value="true"/}
{#eq key=uno value="true"/}
{#any}One of them is "true"{/any}
{#none}None of them is "true"{/none}
{/select}
P.S. I couldn't compare boolean values, but if I pass boolean value true as a string "true", it works perfectly.

How to Update Parts of a document in Couchbase

In scanning the docs I cannot find how to update part of a document.
for example - say the whole document looks like this:
{
"Active": true,
"Barcode": "123456789",
"BrandID": "9f3751ef-f14f-464a-bb86-854e99cf14c0",
"BuyCurrencyOverride": ".37",
"BuyDiscountAmount": "45.00",
"ID": "003565a3-4a0d-47d9-befb-0ac642cb8057",
}
but I only want to work with part of the document as I don't want to be selecting / updating the whole document in many cases:
{
"Active": false,
"Barcode": "999999999",
"BrandID": "9f3751ef-f14f-464a-bb86-854e99cf14c0",
"ID": "003565a3-4a0d-47d9-befb-0ac642cb8057",
}
How can I use N1QL to just update those fields? Upsert completely replaces the whole document and update statement is not that clear.
Thanks
The answer to your question depends on why you want to update only part of the document (e.g., are you concerned about network bandwidth?), and how you want to perform the update (e.g., from the web console? from a program using the SDK?).
The 4.5 sub-document API, for which you provided a link in your comment, is a feature only available via the SDK (e.g., from Go or Java programs), and the goal of that feature is to reduce network bandwidth by no transmitting entire documents around. Does your use case include programmatic document modifications via the SDK? If so, then the sub-document API is a good way to go.
Using the "UPDATE" statement in N1QL is a good way to change any number of documents that match a pattern for which you can specify a "WHERE" clause. As noted above, it works very similarly to the "UPDATE" statement in SQL. To use your example above, you could change the "Active" field to false in any documents where the BuyDiscountAmount was "45.00":
UPDATE my bucket SET Active = false WHERE BuyDiscountAmount = "45.00"
When running N1QL UPDATE queries, almost all the network traffic will be between the Query, Index, and Data nodes of your cluster, so a N1QL update does not cause much network traffic into/out-of your cluster.
If you provide more details about your use case, and why you want to update only part of your documents, I could provide more specific advice on the right approach to take.
The sub-doc API introduced in Couchbase4.5 is currently not used by N1QL. However, when you use the UPDATE statement to update parts of one or more documents.
http://developer.couchbase.com/documentation/server/current/n1ql/n1ql-language-reference/update.html
Let me know any Qs.
-Prasad
It is simple like sql query.
update `Employee` set District='SambalPur' where EmpId="1003"
and here is the responce
{
"Employee": {
"Country": "India",
"District": "SambalPur",
"EmpId": "1003",
"EmpName": "shyam",
"Location": "New-Delhi"
}
}

How get creation and modification date in Orion

I want to get the entity creation and update dates. Following the answer to this question, I should get them with
GET /v2/entities/myEntity?options=dateCreated,dateModified
In another source, the v2 reference, under the Virtual Attributes section, the options are slighter different: dateCreation and dateModification.
However, no matter which option I use, I always get the error answer:
{
"error": "BadRequest",
"description": "Invalid value for URI param /options/"
}
How can I get them?
Note: I'm using version 0.26 due to Proton/xml compatibility.
The dateCreated and dateModified options were introduced in Orion 0.28.0:
Add: dateCreated and dateModified options to get entity creation and modification times as "virtual" attributes (Issue #876)
Thus, you should upgrade Orion to that version. Note that Orion 0.28.0 stills supporting XML (in fact, it will be the last release supporting it).