this is my first time using mongoDB and database. I have a json file like as image below, I want to get only the name of employee who is UX Designer. So far I know how to get the all detail of her by using db.collection.find({ "info.job": "UX Designer" }). Could anyone help me to display only her name
image of json file
Just pass fields that you want to be returned as a second parameter to the find() method:
db.collection.find({ "info.job": "UX Designer" }, { name: 1 })
Note: You can pass key/value pairs, where you will specify property names as keys, and values should be 1 if you want these fields to be returned.
Related
I have a JSON field which I am experimenting with but I am having a bit of trouble with it.
I have added the following to my Customer model:
protected $casts = [
'billingConfig' => 'array'
];
And I updated a test field using the following in my controller:
$customer->billingConfig = ['attachableType' => $request->attachmentsConfig];
$customer->save();
After this, the following appears in my database:
{"attachableType": "combined"}
Now, when I go to grab this specific value through my blade:
{{$customer->billingConfig->attachableType}}
I get "Trying to get property 'attachableType' of non-object"
But when I use the below:
{{$customer->billingConfig['attachableType']}}
I get the "combined" value I was looking for.
I was using this guide: https://www.qcode.in/use-mysql-json-field-in-laravel/, and I guess I wanted to make sure I was doing everything right and their method was wrong or I had goofed up somewhere.
JSON data fields are being read as an array, which you can not call a property for, that's what I believe the reason for the error you got when called
{{$customer->billingConfig->attachableType}}
because it's an array, not a data object (like the case in javascript).
Thanks for sharing.
please find the attached json:
"0":"10000267",
"no":"10000267",
"1":"2180100151-1-40",
"article_no":"2180100151-1-40",
"2":"550053",
"agent_code":"550053",
"3":"103896",
"customer_code":"103896",
"4":"A+",
"grade":"A+",
"5":"1336489",
"id":"1336489",
"6":"8907679958231",
"ean_code":"8907679958231",
"7":"315",
"quantity":"315",
"8":"27",
"available_quantity":"27"
},
{
"0":"10000286",
"no":"10000286",
"1":"2180100151-1-40",
"article_no":"2180100151-1-40",
"2":"550108",
"agent_code":"550108",
"3":"112230",
"customer_code":"112230",
"4":"A+",
"grade":"A+",
"5":"1432890",
"id":"1432890",
"6":"8907679958231",
"ean_code":"8907679958231",
"7":"494",
"quantity":"494",
"8":"27",
"available_quantity":"27"
Now i have extracted "id" using JSON extractor and i have to pass these multiple ids in next request . How can i do this?
For Eg: I have to pass id in next request in this format id=1432890,1336489.How can i achieve this.If any one add a code that can help to achieve this it would be great.
Call the variable by their names in the next request like ${varJson_1},${varJson_2}. So, in the next request id=${varJson_1},${varJson_2}.
If you are using json extractor to fetch multiple values then below screenshot will help you to get all the values in one variable. Then, in the next request call that variable.
As shown below, foo_All contains all the values fetched by the json in one variable. Use this in the next.
Hope this helps.
Can anybody please explain how I can use Angular (4) route params to filter a JSON object to only return 1 record (so I only want to show more specific details, bit like an admin panel). All the examples I've seen just seem to show you how to console.log the param id from the url and don't really go much further (or if they do it isn't explained as clearly as I would like).
What I want to do is I have a JSON object say
{id: 1, name:"Dave"}, {id:2, name: "Steve"}
How can I use the route param in a service to show only the name based upon the id I pass in the url?
name/1
So this example would give me access to the first set of records.
Thanks
I have a json file with the following structure:
{
"0.0.1":{
"version":"0.0.1",
"date_created":"2014-03-15"
},
"0.1.2":{
"version":"0.1.2",
"date_created":"2014-05-21"
}
}
As you can see the whole json file contains just one object which is a map in which each key is the version number and the value is a new map with version and date_created properties.
I want to use Apache Drill to get a list with two columns: version and date_created
But since the keys contain dots (e.g. "0.0.1") Drill throws the following error:
Error: SYSTEM ERROR: UnsupportedOperationException: Unhandled field reference "0.0.1"; a field reference identifier must not have the form of a qualified name (i.e., with ".").
... when running a query like this:
SELECT KVGEN(t.*) FROM dfs.`D:/drill/sample-data/myjsonfile.json` AS t;
By the way, how do you tell KVGEN to process the WHOLE ROW since the row object is the actual map we want to convert?
Any ideas about how to overcome this problem?
UPDATE:
Are all the map keys always different? yes they are. But I think that even in the case they were not, Drill should process them anyway and whenever it would find a duplicate, it should keep the last one (which normally is supposed to be the most recent one for most cases).
The main problem is that the JSON file contains ONLY one big object so there is only 1 record (row) and all its properties are the actual keys to each version data. So there are NO subproperties to navigate to when using KVGEN; the idea is that KVGEN processes the WHOLE record object and not a subproperty of it.
As someone has requested to get more sample data, here it is below:
{
"0.0.1":{
"version":"0.0.1",
"date_created":"2014-03-15"
},
"0.1.2":{
"version":"0.1.2",
"date_created":"2014-05-21"
},
"0.1.5":{
"version":"0.1.5",
"date_created":"2014-05-29"
},
"0.1.7":{
"version":"0.1.7",
"date_created":"2014-06-13"
},
"1.0.0":{
"version":"1.0.0",
"date_created":"2014-07-05"
},
"1.1.0":{
"version":"1.1.0",
"date_created":"2014-09-02"
}
}
I am using the extension library's rest control to provide a json data feed. Is it possible to filter by a category or a field with a URL parameter?
I understand that I can use a search string "&search=something" but that can provide me with erroneous results. I have tried searching for a field equal to some value but that doesn't seem to work for me.
If I cannot do this with the rest control, is it possible with Domino Data Services?
You can filter by a category or field value in a viewJsonService if you add ?keys=yourValue to URL.
The REST service returns the same documents as you would get with view.getAllDocumentsByKey("yourValue").
Default is non-exact-match filtering which means that only the beginning of column value has to match. If you want the exact match then add &keysexactmatch=true to URL which would be the equivalent to view.getAllDocumentsByKey("yourValue", true).
Example:
Assuming, we have a view "Forms" with a first sorted column "Form".
With the REST service
<xe:restService
id="restService1"
pathInfo="DocsByForm">
<xe:this.service>
<xe:viewJsonService
viewName="Forms"
defaultColumns="true">
</xe:viewJsonService>
</xe:this.service>
</xe:restService>
and the URL
http://server/database.nsf/RestServices.xsp/DocsByForm?keys=Memo&keysexactmatch=true
we'd get all documents with Form="Memo" as JSON
[
{
"#entryid":"7-D5029CB83351A9A6C1257D820031E927",
"#unid":"D5029CB83351A9A6C1257D820031E927",
"#noteid":"11DA",
"#position":"7",
"#siblings":14,
"#form":"Memo",
"Form":"Memo",
... other columns ...
},
... other documents
]
We'd get the same result if the first column is categorized.