IF statement in Couchbase Map of view - I'm sure I'm missing something simple - couchbase

I'm trying to limit the map in my view to a specific set of documents by either having the id "startsWith" a string or based on there being a specific node in the JSON> I can't seem to get a result set once I add an IF statement. The reduce is a simple _count:
function(doc, meta) {
if (doc.metricType == "Limit_Exceeded") {
emit([doc.ownedByCustomerNumber, doc.componentProduct.category], meta.id);
}
}
I've also tried if (doc.metricType) and also if(meta.id.startsWith("Turnaway:")
Example Doc:
{
"OvidUserId": 26105400,
"id": "Turnaway:00005792:10562440",
"ipAddress": "111187081038",
"journalTurnawayNumber": 10562440,
"metricType": "Limit_Exceeded",
"oaCode": "OA_Gold",
"orderNumber": 683980,
"ovidGroupID": 3113900,
"ovidGroupName": "tnu999",
"ovidUserName": "tnu999",
"ownedByCustomerNumber": 59310,
"platform": "Lippincott",
"samlString": "",
"serialName": "00005792",
"sessionID": "857616ee-dab7-43d0-a08b-abb2482297dd",
"soldProduct": {
"category": "Multidisciplinary Subjects",
"name": "Custom Collection For CALIS - LWW TA 2020",
"productCode": "CCFCCSI20",
"productNumber": 33410,
"subCategory": "",
"subject": "Multidisciplinary Subjects"
},
"soldToCustomer": {
"customerNumber": 59310,
"keyAccount": false,
"name": "Tongji University"
},
"turnawayDateTime": "2022-05-04T03:01:44.600",
"usedByCustomer": {
"customerNumber": 59310,
"keyAccount": false,
"name": "Tongji University"
},
"usedByCustomerNumber": 59310,
"yearMonth": "202205"
},
"id": "Turnaway:00005792:10562440"
}
Thanks,
Gerry

Found it (of course after posting the question) The second component of the Key in the emit has to exist. I entered doc.componentProduct.category instead of doc.soldProduct.Category.

Related

How to operate with json list in CMake?

I have the following code which I'm trying to read in CMake.
{
"demo": [
{
"name": "foo0",
"url": "url1",
"verify_ssl": true
},
{
"name": "foo1",
"url": "url1",
"verify_ssl": true
},
{
"name": "foo2",
"url": "url2",
"verify_ssl": true
}
]
}
I'm trying to access a member from the list above, for example demo[0].name without success, what I'm doing wrong?
file(READ "${CONAN_CACHE}/demo.json" MY_JSON_STRING)
string(JSON CUR_NAME GET ${MY_JSON_STRING} demo[0].name)
One at a time.
string(JSON CUR_NAME GET ${MY_JSON_STRING} demo 0 name)

Debitoor API is returning 400 bad request

I would like to create invoices by my PHP script. But before I am able to program this I would like to understand the API from Debitoor.
In order to create an invoice you have to create a draft invoice first. You can find this here: /api/sales/draftinvoices/v3.
I have set all the requested parameters to use the the /api/sales/draftinvoices/v3 function however, I always get a 400 Bad Request response back.. The reason is the schema.
Can you guys tell me where my failure is?
I would guess is something with the "lines"... but I would say it's all correct...
This is my request:
Request as text:
{
"date": "2018-05-06",
"dueDate": "2018-05-13",
"notes": "Diese Rechnung ist vom Backend erstellt worden.",
"customerName": "Max Mustermann",
"customerAddress": "Mustermann Stra\u00dfe",
"customerCountry": "DE",
"currency": "EUR",
"languageCode": "de-DE",
"recargoTaxEnabled": false,
"sent": false,
"viewed": false,
"displayAsPaid": false,
"lines": {
"taxEnabled": "false",
"description": "Leistungszeitraum 06.04.2018 - 05.05.2018",
"taxRate": "1.19",
"productOrService": "product"
}
}
This is the response I get back:
As text:
{
"message": "Error validating against schema",
"id": "9905636b-fb65-41a0-8d25-4aa096d5347d",
"code": "schema",
"errors": [
{
"message": "is the wrong type",
"value": {
"taxEnabled": "false",
"description": "Leistungszeitraum 06.04.2018 - 05.05.2018",
"taxRate": "1.19",
"productOrService": "product"
},
"type": "array",
"property": "lines"
}
],
"body": {
"date": "2018-05-06",
"dueDate": "2018-05-13",
"notes": "Diese Rechnung ist vom Backend erstellt worden.",
"customerName": "Max Mustermann",
"customerAddress": "Mustermann Stra\u00dfe",
"customerCountry": "DE",
"currency": "EUR",
"languageCode": "de-DE",
"recargoTaxEnabled": false,
"sent": false,
"viewed": false,
"displayAsPaid": false,
"lines": {
"taxEnabled": "false",
"description": "Leistungszeitraum 06.04.2018 - 05.05.2018",
"taxRate": "1.19",
"productOrService": "product"
}
}
}
Kind regards and Thank You!
Thank you for using the Debitoor API
You are correct. Your problem is with the lines. Lines should be an array. You have only send a single object.
Another issue is that you provide taxEnabled: false and taxRate: 1.19. If you provide taxEnabled as false you should set the taxRate to 0. Remember that taxRate should be between 0 and 100 with a maximum of two decimals
Your request should look something like this instead:
{
"lines": [
{
"taxEnabled": false,
"description": "Leistungszeitraum 06.04.2018 - 05.05.2018",
"taxRate": 0,
"quantity": 1,
"unitNetPrice": 1,
"productOrService": "product"
}
]
Best regards,
Carsten
Mobile developer # Debitoor

dynamic id and special characters for serialization with flat buffers

I have Json data like below
{
"!type": "alarm",
"$": {
"12279": {
"!type": "alarm",
"title": "Default",
"$": {
"5955": {
"!type": "alarm",
"name": "Wake",
"day": "SUN",
"startTime": "06:00"
},
"29323": {
"!type": "alarm",
"name": "Away",
"day": "SUN",
"startTime": "08:00"
},
"2238": {
"!type": "alarm",
"name": "Home",
"day": "SUN",
"startTime": "18:00"
}
}
}
}
}
My fbs looks like this
namespace space.alarm;
table Atom{
!type:string;
name:string;
startDay:string;
startTime:string; }
table AtomShell{
key:string (required, key);
value: Atom; }
table Alarm{
!type:string;
title:string;
$:[AtomShell]; }
table AlarmShell{
key:string (required, key);
value:Alarm; }
table Weeklyalarm{
!type:string;
$:[AlarmShell]; } root_type Weeklyalarm;
Im trying to implement google flat buffers but I'm getting errors like
alarm.fbs:4:0: error: illegal character: !
alarm.fbs:23:0: error: illegal character: $ (i have removed ! from
!type and changed $ to dollar to test the working of flat buffers
but i can't change the dynamic ids )
Sample.json:25:0: error: unknown field: 12279
Now my question,
Is it possible to use dynamic ids in flat buffers, if possible how
shall i proceed?
Can is use special characters in ids, if possible how to do it?
Thanks in advance.
You can't have characters like ! and $ in field names. Just use type instead of !type, etc.
Not sure what you mean by dynamic ids. All field names (keys) have to be declared in the schema, so they can't be dynamic. You can still achieve similar results though, if you make your JSON look something like this:
{
"type": "alarm",
"data": [
{
id: "12279",
"type": "alarm",
"title": "Default",
"data": [
{
"id": "5955",
"type": "alarm",
"name": "Wake",
"day": "SUN",
"startTime": "06:00"
},
{
"id": "29323",
"type": "alarm",
"name": "Away",
"day": "SUN",
"startTime": "08:00"
},
{
"id": "2238",
"type": "alarm",
"name": "Home",
"day": "SUN",
"startTime": "18:00"
}
]
}
]
}
And then make the corresponding schema.
Note that I made the "dynamic" list into a vector, and moved the id into the object itself.
Other tip: string values that are not dynamic (like "alarm") will take up way less space if you make them into an enum instead.

finding document in mongodb with specific id and username

{
"data": [
{
"_id": 555,
"username": "jackson",
"status": "i am coding",
"comments": [
{
"user": "bob",
"comment": "bob me "
},
{
"user": "daniel",
"comment": "bob the builder"
},
{
"user": "jesus",
"comment": "bob the builder"
},
{
"user": "hunter",
"comment": "bob the builder"
},
{
"user": "jeo",
"comment": "bob the builder"
},
{
"user": "jill",
"comment": "bob the builder"
}
]
}
]
}
so i want to get the result with _id :555 and user:bob i tried with below code but i cant make it work it returns empty array
app.get('/all',function(req , res){
db.facebook.find({_id:555},{comments:[{user:"bob"}]},function(err,docs){res.send(docs,{data:docs});});
} );
i want the result to be like this listed below with the comment with user:bob
{
"_id": 555,
"username": "jackson",
"status": "i am coding",
"comments": [
{
"user": "bob",
"comment": "bob me "
}
]
}
Only aggregate or mapReduce could exclude items from subarray in output. Shortest is to use $redact:
db.facebook.aggregate({
$redact:{
$cond:{
if:{$and:[{$not:"$username"},{$ne:["$user","bob"]}]},
then: "$$PRUNE",
else: "$$DESCEND"
}
}
})
Explanation:
$reduct would be applied to each subdocument starting from whole document. For each subdocument $reduct would either prune it or descend. We want to keep top level document, that is why we have {$not:"$username"} condition. It prevents top level document from pruning. On next level we have comments array. $prune would apply condition to each item of comments array. First condition {$not:"$username"} is true for all comments, and second condition {$ne:["$user","bob"]} is true for all subdocuments where user!="bob", so such documents would be pruned.
Update: in node.js with mongodb native driver
db.facebook.aggregate([{
$redact:{
$cond:{
if:{$and:[{$not:"$username"},{$ne:["$user","bob"]}]},
then: "$$PRUNE",
else: "$$DESCEND"
}
}
}], function(err,docs){})
One more thing: $prune is new operator and available only in MongoDB 2.6

Backbone.js Collections

I am working with backbone.js. I am trying to send a request to restful service i am getting the resultset as json object as shown
{
"Msgs": [
"Alert",
"Not"
],
"MessageStatus": [
"Active",
"Inactive"
],
"date": {
"From": "2013-04-25",
"To": "2013-06-25"
},
"Mlist": {
"Status": "PND",
"Role": "Admin,User",
"To": "2013-06-24",
"Id": 6,
"Datecreated": "2013-06-24",
"Title": "Title5",
"From": "2013-06-20"
}
}.
I am putting the json object extracting and setting it to collection but I am not able to get particular model from the collection with specific id.
If you want to make your model can be identified with id. You have to set the id in the attributes hash:
{
"id": 1001,
"Msgs": [
"Alert",
"Not"
],
"MessageStatus": [
"Active",
"Inactive"
],
"date": {
"From": "2013-04-25",
"To": "2013-06-25"
},
"Mlist": {
"Status": "PND",
"Role": "Admin,User",
"To": "2013-06-24",
"Id": 6,
"Datecreated": "2013-06-24",
"Title": "Title5",
"From": "2013-06-20"
}
}
Then using backbone collection "findWhere" method to get the specific id model.
//assume msgCollection is which you put the models
var model = msgCollection.findWhere({id: 1001});
Hope this is helpful for you.
I think you need to set your model and parse your input data. Checkout http://backbonejs.org/#Collection-model, http://backbonejs.org/#Model-parse and http://backbonejs.org/#Collection-parse.