I have Couchbase where documents are stored in json format
like
QueueMessage/abc123
QueueMessage/pqr456
and content in this for QueueMessage/abc123
{
"queue_list": {
"type": "cards.create",
"id": "abc123",
"userId": "abcd",
"deviceId": "abcd-1dg",
"status": "Accepted"
},
"id": "abc123"
}
and for QueueMessage/pqr456
{
"queue_list": {
"type": "cards.create",
"id": "pqr456",
"userId": "pqr",
"deviceId": "abcd-78n",
"status": "Accepted"
},
"id": "pqr456"
}
I want to create couchbase views using userid and device id. how can i do this in ruby?
require 'couchbase'
#Connect to qlists bucket:
client = Couchbase.new(
node_list: ['127.0.0.1:8091'],
bucket: 'qlists',
username: '7stud',
password: 'abc123'
)
#Enter some data in the qlists bucket:
client['QueueMessage/abc123'] = {
"queue_list": {
"type": "cards.create",
"id": "abc123",
"userId": "abcd",
"deviceId": "abcd-1dg",
"status": "Accepted"
},
"id": "abc123"
}
client['QueueMessage/pqr456'] = {
"queue_list": {
"type": "cards.create",
"id": "pqr456",
"userId": "pqr",
"deviceId": "abcd-78n",
"status": "Accepted"
},
"id": "pqr456"
}
#Create a view:
view_doc = %q[
{
"_id": "_design/qlists",
"language": "javascript",
"views": {
"userId_deviceId": {
"map": "function(doc){ emit(doc.queue_list.userId, doc.queue_list.deviceId); }"
}
}
}
]
client.save_design_doc(view_doc)
#Use the view to retrieve data:
qlists = client.design_docs['qlists']
qlists.userId_deviceId.each do |row|
puts "#{row.key}, #{row.value}"
end
--output:--
abcd, abcd-1dg
pqr, abcd-78n
I could not get reduce to work in a view.
Related
I'm very new to OpenAPI and I'm using http://editor.swagger.io to design an API.
I'm stuck in Schema with a JSON looking like following
{
"CORRELATION_ID": "10",
"CONTROL":
{
"DAS_IS_RECIPIENT": "123",
"DOCTPYE": "ert",
"PROCESS_INDICATOR": "nord"
},
"HEADER":
{
"ID": "456",
"INVOICE_NUMBER": "678",
"DMS_DOC_ID": "876",
"INVOICE_DATE": "10082020"
},
"ITEMS": [
{
"SHORT_TEXT": "123",
"LSTAR": 0,
"QUANTITY": "23"
},
{
"SHORT_TEXT": "456",
"LSTAR": 234,
"QUANTITY": "21"
}
],
"DEBITOR":
{
"ID": "444",
"FIRSTNAME": "nick",
"LASTNAME": "cantre"
},
"CREDITOR":
{
"ID": "454",
"FIRSTNAME": "ava",
"LASTNAME": "pierre"
}
}
How to create a schema according to this JSON structure?
I created a SharePoint Page in SitePages library using the new SharePoint online experience. The page was created and I tried to fetch the page properties using MS Graph endpoint:
https://graph.microsoft.com/v1.0/drives/{drive-id}/root:/site_page.aspx?expand=listItem
The response I got:
{
...
"name": "site_page.aspx",
...
"file": {
"mimeType": "application/xml",
"hashes": {
"quickXorHash": ""
}
},
...
"listItem": {
...
"id": "4",
...
"contentType": {
"id": "0x0101009D1CB255DA76424F860D91F20E6C411800020BAE24978F3545AFD24007B325ACF9"
},
"fields": {
"FileLeafRef": "site_page.aspx",
"Title": "site_page",
"LinkTitle": "site_page",
"id": "4",
"ContentType": "Site Page",
...
}
}
}
Then I added Wiki Page content to this library to support Wiki pages in my site.
I created a new Wiki Page and fetched the page properties again using MS Graph endpoint:
https://graph.microsoft.com/v1.0/drives/{drive-id}/root:/wiki_page.aspx?expand=listItem
The response I got:
{
...
"name": "wiki_page.aspx",
...
"file": {
"mimeType": "application/xml"
},
...
"listItem": {
...
"id": "5",
...
"contentType": {
"id": "0x0101009D1CB255DA76424F860D91F20E6C411800020BAE24978F3545AFD24007B325ACF9"
},
"fields": {
"FileLeafRef": "wiki_page.aspx",
"Title": "wiki_page",
"LinkTitle": "wiki_page",
"id": "5",
"ContentType": "Site Page",
"WikiField" : "..."
...
}
}
}
As you can see both items have the same Content Type. How that is possible?
The only difference being that the wiki_page Item doesn't include 'hashes' property and does include 'WikiField' property (the place where the wiki page content is stored).
Is there another way to distinguish page types?
You could try this endpoint: GET /sites/{site-id}/lists/{list-id}/items?expand=fields(select= ContentType)
My test result:
{
"#odata.etag": "\"b3b04ace-40cd-4847-a3d8-678bc658216d,2\"",
"createdDateTime": "2020-04-22T05:34:06Z",
"eTag": "\"b3b04ace-40cd-4847-a3d8-678bc658216d,2\"",
"id": "11",
"lastModifiedDateTime": "2020-04-22T05:34:06Z",
"webUrl": "https://xxxx.sharepoint.com/sites/dev/SitePages/wikipage.aspx",
"createdBy": {
"user": {
"email": "amos#xxxx.onmicrosoft.com",
"id": "fc1e9add-6f9c-4b95-83e1-a022441681d7",
"displayName": "test"
}
},
"lastModifiedBy": {
"user": {
"email": "amos#xxxx.onmicrosoft.com",
"id": "fc1e9add-6f9c-4b95-83e1-a022441681d7",
"displayName": "test"
}
},
"parentReference": {
"id": "79e13173-d5ee-4a17-a081-5c94d148f905",
"siteId": "xxxx.sharepoint.com,b57886ef-4c2a-4d56-ad29-27266638ac3b,b62d1450-8e6f-4be7-84a3-f6600fd6cc14"
},
"contentType": {
"id": "0x01010800511BB12BD4FB664A89516226DBDDF1FB"
},
"fields#odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites('siteid')/lists('63307f0b-bc1c-4372-bfea-6352ed57a0ff')/items('11')/fields/$entity",
"fields": {
"#odata.etag": "\"b3b04ace-40cd-4847-a3d8-678bc658216d,2\"",
"ContentType": "Wiki Page"
}
},
{
"#odata.etag": "\"70f12845-7646-4b2b-85bd-4a8074c105a0,1\"",
"createdDateTime": "2020-04-22T05:35:54Z",
"eTag": "\"70f12845-7646-4b2b-85bd-4a8074c105a0,1\"",
"id": "12",
"lastModifiedDateTime": "2020-04-22T05:35:54Z",
"webUrl": "https://xxxx.sharepoint.com/sites/dev/SitePages/webpartpage.aspx",
"createdBy": {
"user": {
"email": "amos#xxxx.onmicrosoft.com",
"id": "fc1e9add-6f9c-4b95-83e1-a022441681d7",
"displayName": "test"
}
},
"lastModifiedBy": {
"user": {
"email": "amos#xxxx.onmicrosoft.com",
"id": "fc1e9add-6f9c-4b95-83e1-a022441681d7",
"displayName": "test"
}
},
"parentReference": {
"id": "79e13173-d5ee-4a17-a081-5c94d148f905",
"siteId": "xxxx.sharepoint.com,b57886ef-4c2a-4d56-ad29-27266638ac3b,b62d1450-8e6f-4be7-84a3-f6600fd6cc14"
},
"contentType": {
"id": "0x0101090100FAC6DAD225005749BE7D6124B50B156E"
},
"fields#odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites('siteid')/lists('63307f0b-bc1c-4372-bfea-6352ed57a0ff')/items('12')/fields/$entity",
"fields": {
"#odata.etag": "\"70f12845-7646-4b2b-85bd-4a8074c105a0,1\"",
"ContentType": "Web Part Page"
}
}
You'd better check the type of your page.
Updatded:
"fields#odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites('siteid')/lists('63307f0b-bc1c-4372-bfea-6352ed57a0ff')/items('13')/fields/$entity"
"fields": {
"#odata.etag": "\"18361706-416b-4a71-8d31-bce87c1a57e4,3\"",
"ContentType": "Site Page"
}
in official docs: https://docs.graphene-python.org/projects/django/en/latest/queries/#default-queryset. In practice nothing happens. Please help. Below, for example i have just simple part of code with model Contact that have 3 fields(id, kind, value). I want the ContactType to always be filtered with kind='PHONE'.
class ContactType(DjangoObjectType):
class Meta:
model = Contact
#classmethod
def get_queryset(cls, queryset, info):
return queryset.filter(kind='PHONE')
class ContactQuery(graphene.ObjectType):
contacts = graphene.List(ContactType)
def resolve_contacts(self, info, **kwargs):
return Contact.objects.all()
The query:
{
contacts {
id
kind
value
}
}
returns:
{
"data": {
"contacts": [
{
"id": "1",
"kind": "INSTAGRAM",
"value": "technodomkz"
},
{
"id": "3",
"kind": "YOUTUBE",
"value": "UCF-HjvMMvgnhXhO4shk9i9Q"
},
{
"id": "4",
"kind": "FACEBOOK",
"value": "technodomkz"
},
{
"id": "5",
"kind": "TWITTER",
"value": "technodom_kz"
},
{
"id": "6",
"kind": "PHONE",
"value": "88000801111"
},
{
"id": "7",
"kind": "PHONE",
"value": "87272799999"
},
{
"id": "8",
"kind": "EMAIL",
"value": "callcenter#technodom.kz"
},
{
"id": "2",
"kind": "WEBSITE",
"value": "www.technodom.kz"
}
]
}
}
instead of:
{
"data": {
"contacts": [
{
"id": "6",
"kind": "PHONE",
"value": "88000801111"
},
{
"id": "7",
"kind": "PHONE",
"value": "87272799999"
}
]
}
}
For anyone looking for the answer to this question, it is answered here
Try swapping out List for DjangoConnectionField.
Looks like we need to document that get_queryset works with the DjangoConnectionField and that non-relay fields like List don't have the same magic.
I'm using swagger for quite a bit now, we have started documenting our code using it, in one place there's an API response which returns multiple objects in the included block.
Example:
{
"data": {
"id": "1",
"type": "schoolPositions",
"attributes": {
"description": "teases the students",
"mustHaves": "principle"
},
"relationships": {
"schoolLocation": {
"data": {
"id": "72",
"type": "schoolLocations"
}
},
"schoolCompensation": {
"data": {
"id": "75",
"type": "schoolCompensations"
}
},
"jobSpecs": {
"data": [
{
"id": "82",
"type": "schoolAttachments"
}
]
}
}
},
"included": [
{
"id": "72",
"type": "schoolLocations",
"attributes": {
"city": "Berhampore",
"state": "West Bengal",
"postalCode": "742101",
"country": "India",
"globalRegionId": 30,
"regionId": 683
}
},
{
"id": "75",
"type": "schoolCompensations",
"attributes": {
"salary": "",
"bonus": "",
"equity": "",
"currencyId": null,
"equityType": "percent",
"salaryDescription": null
}
},
{
"id": "82",
"type": "schoolAttachments",
"attributes": {
"attachmentType": "JobSpecificationAttachmentType",
"fileFileName": "vs.jpg",
"fileContentType": "image/jpeg",
"fileFileSize": 2410039,
"fileUpdatedAt": "2018-12-12T07:06:38Z",
"downloadUrl": "001-vs.jpg?1544598398",
"klass": "SchoolAttachments"
}
}
]
I have wasted an entire day on the internet and documentation trying to document the included part, but I'm going wrong somewhere
response 200 do
key :description, 'School Data'
schema do
property :data do
key :type, :array
items do
key :'$ref', :School
end
end
property :included do
key :type, :array
items do
key :'$ref', :SchoolLocations
key :'$ref', :SchoolCompensations
key :'$ref', :SchoolAttachments
end
end
end
end
This shows only the SchoolAttachments in the included part.
I have tried using allOff but it doesn't work.
For example I need to represent following structure in swagger yaml format:
"included": [
{
"type": "people",
"id": "42",
"attributes": {
"name": "John",
"age": 80,
"gender": "male"
}
}
]
With single object everything is fine:
included:
type: "array"
items:
type: object
properties:
type:
type: "string"
# and so on
The question is what if I need to describe something like:
"included": [{
"type": "people",
"id": "9",
"attributes": {
"first-name": "Dan",
"last-name": "Gebhardt",
"twitter": "dgeb"
},
"links": {
"self": "http://example.com/people/9"
}
}, {
"type": "comments",
"id": "5",
"attributes": {
"body": "First!"
},
"relationships": {
"author": {
"data": { "type": "people", "id": "2" }
}
},
"links": {
"self": "http://example.com/comments/5"
}
}, {
"type": "comments",
"id": "12",
"attributes": {
"body": "I like XML better"
},
"relationships": {
"author": {
"data": { "type": "people", "id": "9" }
}
},
"links": {
"self": "http://example.com/comments/12"
}
}]
I know that in OpenAPI it's possible ( aka swagger 3 ) and tried some workarounds in current version but with no luck.