Lets say we have an entity with attributes A,B,C,D. Can we update only some of them, for example only B and D, or we have to update all of them, or just only one? And if it's possible to update some of them, how the target url must be constructed for the request to work?
You can update only a subset of attributes if you want. For instance:
PATCH /v2/entities/E1/attrs
{
"B": {
"value": "foo",
"type": "Text"
},
"D": {
"value": "bar",
"type": "Text"
}
}
which updates B and D but leave A and C untouched. You can use POST instead of PATCH: the former does update or create if the attribute doesn't exist in the entity, the later is for strict update (if the attribute to update doesn't exist, you will get an error response).
This and more detail can be found in the NGSIv2 specification document.
Related
if /wallet returns a list a wallets and each wallet has a list of transactions. What is the standard OpenAPI/REST standard?
For example,
http://localhost:8000/api/wallets/ gives me
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"user": 1,
"address": "3E8ociqZa9mZUSwGdSmAEMAoAxBK3FNDcd",
"balance": "2627199.00000000"
}
]
}
http://localhost:8000/api/wallets/3E8ociqZa9mZUSwGdSmAEMAoAxBK3FNDcd/ gives me
{
"user": 1,
"address": "3E8ociqZa9mZUSwGdSmAEMAoAxBK3FNDcd",
"balance": "2627199.00000000"
}
If I wanted to add a transactions list, what is the standard way to form this?
http://localhost:8000/api/wallets/3E8ociqZa9mZUSwGdSmAEMAoAxBK3FNDcd/transactions ?
http://localhost:8000/api/wallets/3E8ociqZa9mZUSwGdSmAEMAoAxBK3FNDcd/transactions?offset=100 for pagination
REST doesn't care what spelling conventions you use for your resources. What it would instead expect is that you have representations of links between resources, along with meta data describing the nature of the link.
So this schema is fine.
/api/wallets/3E8ociqZa9mZUSwGdSmAEMAoAxBK3FNDcd
/api/wallets/3E8ociqZa9mZUSwGdSmAEMAoAxBK3FNDcd/transactions
And this schema is also fine.
/api/wallets/3E8ociqZa9mZUSwGdSmAEMAoAxBK3FNDcd
/api/transactions/3E8ociqZa9mZUSwGdSmAEMAoAxBK3FNDcd
As far as I can tell, OpenAPI also gives you the freedom to design your resource model the way that works best for you (it just tells you one possible way to document the resource model you have selected).
Using the FIWARE PointOfInterest data model I would like to filter by POI category which is an array. For instance
http://130.206.118.244:1027/v2/entities?type=PointOfInterest&options=keyValues&attrs=name,category&limit=100&q=category=="311"
having as entity instances something like
{
"id": "Museum-f85a8c66d617c23d33847f8110341a29",
"type": "PointOfInterest",
"name": "The Giant Squid Centre",
"category":
[
"311"
]
},
{
"id": "Museum-611f228f42c7fbfa4bd58bad94455055",
"type": "PointOfInterest",
"name": "Museo Extremeño e Iberoamericano de Arte Contemporáneo",
"category":
[
"311"
]
},
Looking to the NGSIv2 specification it seems that works in the way you mention:
Single element, e.g. temperature==40. For an entity to match, it must contain the target property (temperature) and the target property value must be the query value (40) (or include the value, in case the target property value is an array).
I mean, in particular the part that says:
...or include the value, in case the target property value is an array.
I'm very new to MongoDB, i tell you sorry for this question but i have a problem to understand how to create a document that can contain a value with different "type:
My document can contain data like this:
// Example ONE
{
"customer" : "aCustomer",
"type": "TYPE_ONE",
"value": "Value here"
}
// Example TWO
{
"customer": "aCustomer",
"type": "TYPE_TWO",
"value": {
"parameter1": "value for parameter one",
"parameter2": "value for parameter two"
}
}
// Example THREE
{
"customer": "aCustomer",
"type": "TYPE_THREE",
"value": {
"anotherParameter": "another value",
{
"someParameter": "value for some parameter",
...
}
}
}
Customer field will be even present, the type can be different (TYPE_ONE, TYPE_TWO and so on), based on the TYPE the value can be a string, an object, an array etc.
Looking this example, i should create three kind of collections (one for type) or the same collection (for example, a collection named "measurements") can contain differend kind of value on the field "value" ?
Trying some insert in my DB instance i dont get any error (i'm able to insert object, string and array on property value), but i would like to know if is the correct way...
I come from RDBMS, i'm a bit confused right now.. thanks a lot for your support.
You can find the answer here https://docs.mongodb.com/drivers/use-cases/product-catalog
MongoDB's dynamic schema means that each need not conform to the same schema.
As I create entities in an Orion server, I can search by ID, as flat or using regular expressions:
http://<localhost>:1026/v1/queryContext
Content:
{
"entities": [
{
"type": "Sensor",
"isPattern": "true",
"id": "sensor_1.*"
}
],
"attributes": ["temperature","humidity"]
}
In the above example I'd get all objects of type "Sensor" whose ID starts with "sensor_1", and their attributes "temperature" and "humidity". I wonder if there is any way that would allow me to search by specific attribute value, for example to get those sensors whose humidity is over "60.2", or this selection must be done over the retrieved data queried by ID.
Not in the current Orion version (0.19.0) but it will be possible in the future. Have a look to the attribute::<name> filter with the = operator in this document.
I’m trying to use apigility with doctrine’s mongodb odm.
I’ve set up my documents and configured the doctrine module as should.
I’ve inserted (manually) one document to mongo, and defined a code-based rest service, with its “fetch” method (in the resource class) to return the document's repository "find" return value.
When I call the endpoint (without the ID) I get an array of the single document I’ve inserted, but it’s not shown correctly:
{
"_links": {
"self": {
"href": "http://localhost:8888/posts"
}
},
"_embedded": {
"posts": [
{
"\u0000MyApp\\Document\\Post\u0000id": "5389db47075000812e55bd7d",
"\u0000MyApp\\Document\\Post\u0000title": "My Post",
"\u0000MyApp\\Document\\Post\u0000description": "This is my post",
"_links": {
"self": {
"href": "http://localhost:8888/posts/1"
}
}
}
]
},
"total_items": 1
}
There are (at least) two problems with this output:
The key of each property is weirdly formatted. it contains the complete namespace with the document name, and the utf8 code for NULL
The “self” link does not use the correct id (it uses the number 1 instead of the mongodb autogenerated id).
What is wrong/missing ?
This happens when php uses ObjectProperty (\Zend\Stdlib\Hydrator\ObjectProperty )hydrator for populating the Objects.And in Apigility if you dont specify a hydrator then it will fall back to ObjectProperty hydrator(Default), which seems to be the case with your ouput.
Use Classmethods hydrator (\Zend\Stdlib\Hydrator\ClassMethods) instead.