When reading the below JSON data, am getting invalid code sequence exception
in read_json.
{
"_ID":"18",
"_Record":"1",
"_BreakPageMessage":"abcd: 137
Product: ID: 1234
Description: 23456 abcdfm
CustomerId: 23456
Component Id: 3456
Description: 12345 Admn RC - up
count: 40
Sides 2
Tarnish:
size: 125 x 205
Memo:"
}
_BreakPageMessage property has multiple lines. If we give it as single line everything works fine.
This _BreakPageMessage doesn't have any umlaut characters.
boost::property_tree::read_json( file, pt );
Can anyone tell is there anyway to read json that has multiple lines of property data using boost.We are using C++ and boost.
Newlines are not valid characters in JSON strings, your data isn't JSON.
You could escape them
{
"_ID":"18",
"_Record":"1",
"_BreakPageMessage":"abcd: 137\r\n Product: ID: 1234\r\n Description: 23456 abcdfm\r\n CustomerId: 23456\r\n Component Id: 3456\r\n Description: 12345 Admn RC - up\r\n count: 40\r\n Sides 2\r\n Tarnish:\r\n size: 125 x 205\r\n Memo:"
}
or use a sub-object
{
"_ID":"18",
"_Record":"1",
"_BreakPageMessage":{
"abcd": 137,
"Product": { "ID": 1234 },
"Description": "23456 abcdfm",
"CustomerId": "23456",
"Component Id": "3456",
"Description": "12345 Admn RC - up",
"count": "40",
"Sides": "2",
"Tarnish": { size: "125 x 205" },
"Memo":""
}
}
Related
I'm confused. I've just started to write tests with jest, and i cant figure out what is going on. Here is my output:
Expected value to equal:
ObjectContaining {"field": "f1", "module": "m1", "rights": {"read": true}}
Received:
{"_id": "5ae85cd0bc5ad3569bf66df8", "field": "f1", "module": "m1", "rights": {"read": true}}
Difference:
- Expected
+ Received
## -1,6 +1,7 ##
- ObjectContaining {
+ Object {
+ "_id": "5ae85cd0bc5ad3569bf66df8",
"field": "f1",
"module": "m1",
"rights": Object {
"read": true,
},
183 | ]),
184 | );
> 185 | expect(user.acl[0]).toEqual(
186 | expect.objectContaining({ module: 'm1', field: 'f1', rights: {read: true}}),
187 | );
188 | });
I think its failing because user is a mongoose object.
You should remove _id from your object before comparing.
Alternatively, you should use toMatchSnapshot() (but still need to remove any keys that will change on each run.
Looks like you can convert mongoose object to plain object by calling user.toObject() function. And everything works as expected.
I have a set of data like this:
[{name: "ROBERT"}, {name: "PETER"}, {name: "ROBINSON"} , {name: "ABIGAIL"}]
I want to make a single mongodb query that can find:
Any data which name starts with letter "R" (regex: ^R)
Followed by any data which name contains letter "R" NOT AS THE FIRST CHARACTER, like: peteR, adleR, or caRl
so it produces:
[{name: "ROBERT"}, {name: "ROBINSON"}, {name: "PETER"}]
it basically just display any data that contains "R" character in it but I want to sort it so that data with "R" as the first character appears before the rest
So far I've come out with 2 separate query then followed by an operation to eliminate any duplicated results, then joined them. So is there any more efficient way to do this in mongo ?
What you want is add a weight to you documents and sort them accordingly.
First you need to select only those documents that $match your criteria using regular expressions.
To do that, you need to $project your documents and add the "weight" based on the value of the first character of your string using a logical $condition processing.
The condition here is $eq which add weight 1 to the document if the lowercase of the first character in the name is "r" or 0 if it's not.
Of course the $substr and the $toLower string aggregation operators respectively return the the first character in lowercase.
Finally you $sort your documents by weight in descending order.
db.coll.aggregate(
[
{ "$match": { "name": /R/i } },
{ "$project": {
"_id": 0,
"name": 1,
"w": {
"$cond": [
{ "$eq": [
{ "$substr": [ { "$toLower": "$name" }, 0, 1 ] },
"r"
]},
1,
0
]
}
}},
{ "$sort": { "w": -1 } }
]
)
which produces:
{ "name" : "ROBERT", "w" : 1 }
{ "name" : "ROBINSON", "w" : 1 }
{ "name" : "PETER", "w" : 0 }
try this :
db.collectioname.find ("name":/R/)
I'm trying to figure out how to add a filter onto a crossfilter group that is not related to a dimensional filter. Let's look at an example:
var livingThings = crossfilter({
// Fact data.
{ name: “Rusty”, type: “human”, legs: 2 },
{ name: “Alex”, type: “human”, legs: 2 },
{ name: “Lassie”, type: “dog”, legs: 4 },
{ name: “Spot”, type: “dog”, legs: 4 },
{ name: “Polly”, type: “bird”, legs: 2 },
{ name: “Fiona”, type: “plant”, legs: 0 }
}); //taken from http://blog.rusty.io/2012/09/17/crossfilter-tutorial/
if we were to make a dimension on type and a group of that dimension:
var typeDim = livingThings.dimension(function(d){return d.type});
var typeGroup = typeDim.group();
we would expect typeGroup.top(Infinity) to output
{{human:2},
{dog:2},
{bird:1},
{plant:1}}
My question is how can we filter the data such that they include only 4 legged creatures in this grouping? I also don't want to use dimension.filter... because i don't want this filter to be global, just for this one grouping. In other words
var filterDim = livingThings.dimension(function(d){return d.legs}).filterExact(4);
is not allowed.
I'm thinking of something similar to what I did to post-filter dimensions as in https://stackoverflow.com/a/30467216/4624663
basically I want to go into the internals of the typeDim dimension, and filter the data before it is passed into the groups. Creating a fake group that calls typeDim.group().top() will most likely not work as the individual livingThings records are already grouped by that point. I know this is tricky: thanks for any help.
V
Probably best to use the reduceSum functionality to create a pseudo-count group that only counts records with 4 or more legs:
var livingThings = crossfilter({
// Fact data.
{ name: “Rusty”, type: “human”, legs: 2 },
{ name: “Alex”, type: “human”, legs: 2 },
{ name: “Lassie”, type: “dog”, legs: 4 },
{ name: “Spot”, type: “dog”, legs: 4 },
{ name: “Polly”, type: “bird”, legs: 2 },
{ name: “Fiona”, type: “plant”, legs: 0 }
}); //taken from http://blog.rusty.io/2012/09/17/crossfilter-tutorial/
var typeDim = livingThings.dimension(function(d){return d.type});
var typeGroup = typeDim.group().reduceSum(function(d) {
return d.legs === 4 ? 1 : 0;
});
That will sum across a calculated value that will be 1 for records with 4 legs and 0 for records with ... not 4 legs. In other words, it should just count 4-legged creatures.
I think, this is what you are looking for. Comment back if I'm wrong.
var dimByLegs = livingThings.dimension(function(d){return d.legs});
dimByLegs.filterExact(4);
var dogs = dimByLegs.group();
dimByLegs.top(Infinity).forEach(function(d){console.log(d.type, d.legs);});
dimByLegs.dispose();
I am trying to write a view in Couchbase using a reduce such as _count which will give me a count of the products at an address.
I have some documents in the database in the following format;
Document 1
{
id: 1,
address: {
street: 'W Churchill St'
city: 'Chicago',
state: 'IL',
},
product: 'Cable'
}
Document 2
{
id: 2,
address: {
street: 'W Churchill St'
city: 'Chicago',
state: 'IL',
},
product: 'Cable'
}
Document 3
{
id: 3,
address: {
street: 'W Churchill St'
city: 'Chicago',
state: 'IL',
},
product: 'Satellite'
}
Document 4
{
id: 4,
address: {
street: 'E Foster Rd'
city: 'New York',
state: 'NY',
},
product: 'Free To Air'
}
I already have a view which gives me all the products at an address which uses a composite key such as;
emit([doc.address.street, doc.address.city, doc.address.state], null)
Now this leads me on to the actual problem, I want to be able to get a count of products at a address or addresses.
I want to be able to see for an array of "keys"
['W Churchill St','Chicago','IL']
['E Foster Rd','New York','NY']
which products and a count of them. So i would expect to see in my results.
'Cable' : 2,
'Satellite': 1,
'Free To Air': 1
however if I specified only this "key",
['W Churchill St','Chicago','IL']
I would expect to see
'Cable' : 2,
'Satellite': 1
How to write my view to accommodate this?
The solution to this was to append my product to the key like so;
emit([doc.address.street, doc.address.city, doc.address.state, doc.product], null)
Then using;
?start_key=[street,city,state]&end_key=[street,city,state,{}]&group_level=4
Result:
{"rows":[
{"key":['W Churchill St','Chicago','IL','Cable'], "value":2},
{"key":['W Churchill St','Chicago','IL','Satellite'], "value":1}
]}
I would then need to repeat this query for each of the addresses and sum the results.
I'm trying to create some simple custom highlighting in Sublime Text 3 using AAAPackageDev.
In the line
void plastic my_material,
I'd like to match plastic, i.e. the material type, as a keyword and my_material, i.e. the material name, as a string.
I've got the following which however only matches plastic and not the name that follows, i.e. my_material:
// [PackageDev] target_format: plist, ext: tmLanguage
{ "name": "Radiance",
"scopeName": "source.radiance",
"fileTypes": ["rad", "sky", "mat"],
"uuid": "885b4450-d2bb-4a67-aea0-ceb5a0554630",
"patterns": [
{
"name": "keyword.source.radiance",
"match": "\\bplastic\\b | \\blight\\b"
},
{
"name": "keyword.source.radiance",
"begin": "(\\bplastic\\b | \\blight\\b)",
"patterns": [
{ "include": "$self"},
{
"name": "string.source.radiance",
"match": "[^\\s]+"
}],
"end": "\\n"
}]
}
I'm trying to follow these docs here. Any ideas?
EDIT
The full text I'm trying to parse is:
void plastic my_material
0
0
5 0.4 0.25 0.05 0.05 0.03
void and plastic maintain position but might change their value. my_material is just an arbitrary name that could comprise pretty much anything but must follow a keyword from the first pattern and will be followed by a new line.