tMongoDBOutput - Configuring JSON tree - json

Trying to configure JSON tree for tMongoDBOutput. Only 1 element is getting created in subelement array. Can someone please give a example of configuring the JSON tree. Requirement is one document can have multiple nested sub documents. Medical_records can have multiple sub documents, but only 1 sub document is getting created now skipping the rest.
Resulting JSON in MongoDB as follows
{
"first_name" : "testname",
"middle_name" : [],
"last_name" : "test",
"medical_records" : [
{
"dateofuploading" : "2016-09-29 12:49:21.5",
"filename" : "demo.pdf",
"isautogenerated" : "1",
"recordid" : "123"
}
]
}

enter image description hereIf you want to have multiple sub documents in array,You need to use the group by operation in the advance settings for the element inside the array .

Related

How to update the whole array of objects using Put http request with a json raw body?

I have a json Array something like below and I want to make an update to the whole list without passing by a specefic ID.
List before update
[ { id:"1", name : "name_1" }, { id:"2", name : "name_2" } ]
Wanted list after update
[ { id:"1", name : "name_3" }, { id:"2", name : "name_4" } ]
I tried using PUT request and passing the target list in a json raw body, but it always return "404 not found"
I tried it with Postman but it returns the same error. Is it possible to do like so ?

Workaround to add JSON with errors to mongodb atlas collection

In my database class we were given an assignment to work with two JSON files (add them to a mongodb atlas collection and query certain results)
Both JSON files had "errors" the first being :
{ "_id" : { "$oid" : "50b59cd75bed76f46522c34e" }, "student_id" : 0, "class_id" : 2, "scores" : [ { "type" : "exam", "score" : 57.92947112575566 }, { "type" : "quiz", "score" : 21.24542588206755 }, { "type" : "homework", "score" : 68.19567810587429 }, { "type" : "homework", "score" : 67.95019716560351 }, { "type" : "homework", "score" : 18.81037253352722 } ] }
and the second being :
{"_id":0,"name":"aimee Zank","scores":[{"score":1.463179736705023,"type":"exam"},{"score":11.78273309957772,"type":"quiz"},{"score":35.8740349954354,"type":"homework"}]},
{"_id":1,"name":"Aurelia Menendez","scores":[{"score":60.06045071030959,"type":"exam"},{"score":52.79790691903873,"type":"quiz"},{"score":71.76133439165544,"type":"homework"}]},
I fixed error 1 by removing the $oid and replacing it with just oid: as there was an error trying to add objects with $oid as a value to my collection. I also needed to add everything to an array.
I fixed the second by putting the entire object inside an array [].
When I asked my professor why these errors were in the JSON files and if it was on purpose, he said that they were there on for a reason and that we needed to find a "work around".
I am curious what work around there is to load JSON data that is incorrect into a collection? I am at a complete loss as to what he expected. Is there some way I can just load individual objects line by line from the JSON file to the collection?
This is how I loaded the JSON data after fixing the files directly:
const fs = require('fs');
var data = JSON.parse(fs.readFileSync("./students.json"));
JSON.stringify(data);
const database = "college";
const collection = "students";
use(database);
db.students.drop();
db.createCollection(collection);
db.students.insertMany(data);
--- All the importing of data should be done in VS Code and not using --mongodb import
And a side note that this assignment has since passed so I am not asking for help in completing my homework, simply trying to see if there was something I could of done that would not of required me to edit the JSON file itself. My professor has not responded to me regarding this question.

handling a well-formed JSON file of an array of objects

A JSON string string passes the jsonlint test.
response = [
{
"article" : {
"info" : {
"initial" : {
"articleIds" : [
"7461221587662919569"
],
}
},
"text" : "where they would 'transfer to' next.",
"lang" : "en",
}
},
{
"article" : {
"info" : {
"initial" : {
"articleIds" : [
"6613144915874808065"
],
}
},
"text" : "produto regional.",
"lang" : "pt"
}
}
]
However, after processing
require 'json'
file = File.read('/Users/main/jugg//article_samples.js')
data_hash = JSON.parse(file)
One is left with an array, whereas more frequently a hash with a name labels a subsequent array, where one works with that nomenclature such as response['data']
But in this case the array is not accessible via response[0]. How can this be considered as an array in order to process each individual element collection.each do |member|?
A curiosity: data_hash.class => NilClass
The response = ... code from article_samples.js is JavaScript, not JSON. This initializes a variable named response with a JavaScript array.
To use this as JSON, then rename the file to article_samples.json and remove response = from the file. The first line should start with [.
Now your second block of code should work just fine as long as the article_samples.json file is in the correct path.
On a side note, I suggest that you find a way to make the path more flexible. The way you have it currently hard coded is tied directly to your current machine's file system. This won't work if you want to run this code from another machine because the folder /Users/main/jugg probalby won't exist.
If this is a web server with ruby on rails, then one solution is to create an environment variable with the path where this file is stored.

Resolve error on deep insert of navigation property Dynamics WebAPI

I am using the Microsoft Dynamics Web API to write data to an entity in Microsoft Dynamics 365. When I try to do a deep insert I am receiving the error
An undeclared property 'ccseq_employeeid' which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values.
Why am I receiving this error and how can I resolve the error?
JSON
{
"ccseq_importdate" : "2017-05-28T04:00:00Z",
"ccseq_month" : "1",
"ccseq_year" : "2017",
"ccseq_name" : "Test",
"ccseq_status" : "100000000", "ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID" :
[
{
"ccseq_employeeid#odata.bind": "/systemusers(6d2fd71b-32d1-dd11-a4f5-001a6449bbe7)",
"ccseq_clientid#odata.bind": "/ccseq_clients(663ebd00-73b9-4faf-90ed-f56bb9c2dc9b)",
"ccseq_navemployeeid" : "11111",
"ccseq_employeefirstname" : "John"
}
]
}
ExpenseTransactionSet is the parent of ExpenseTransaction meaning that ExpenseTransaction has a lookup to ExpenseTransactionSet. ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID is one to many relationship. systemuser and ccseq_clients are separate entities that are lookups in ExpenseTransaction.
I've also tried the below variations on the "ccseq_employeeid#odata.bind"
objectid_systemuser#odata.bind
objectid_ccseq_employeeid#odata.bind
ccseq_employeeid#data.bind
ccseq_employeeid#odata.bind : systemusers()
ccseq_employeeid_systemusers#odata.bind
systemuserid_systemusers#odata.bind
I have seen this question and this question and tried the suggested resolutions without success.
I discovered the answer reading this thread. The correct syntax for a Navigation Property in a deep insert is to use the Child Entity Name followed by brackets with the field name. The json needs to be changed to the below
{
"ccseq_importdate" : "2017-05-28T04:00:00Z",
"ccseq_month" : "1",
"ccseq_year" : "2017",
"ccseq_name" : "Test",
"ccseq_status" : "100000000",
"ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID" :
[
{
// Next two lines are changed
"ExpenseTransaction[ccseq_employeeid#odata.bind]": "/systemusers(6d2fd71b-32d1-dd11-a4f5-001a6449bbe7)",
"ExpenseTransaction[ccseq_clientid#odata.bind]": "/ccseq_clients(663ebd00-73b9-4faf-90ed-f56bb9c2dc9b)",
"ccseq_navemployeeid" : "11111",
"ccseq_employeefirstname" : "John"
}
]
}
In the metadata document {org-url}/api/data/v8.0/$metadata, can you check the element-type of the collection-valued navigation property ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID?
Is it the same type which has ccseq_employeeid as its navigation property? If not, and the property ccseq_employeeid belongs to the derived type, you may need to annotate the navigation property object as below:
{
"ccseq_importdate" : "2017-05-28T04:00:00Z",
"ccseq_month" : "1",
"ccseq_year" : "2017",
"ccseq_name" : "Test",
"ccseq_status" : "100000000",
"ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID" :
[
{
"#odata.type": "Microsoft.Dynamics.CRM.ccseq_navemployee",
"ccseq_employeeid#odata.bind": "/systemusers(6d2fd71b-32d1-dd11-a4f5-001a6449bbe7)",
"ccseq_clientid#odata.bind": "/ccseq_clients(663ebd00-73b9-4faf-90ed-f56bb9c2dc9b)",
"ccseq_navemployeeid" : "11111",
"ccseq_employeefirstname" : "John"
}
]
}

Salesforce JSON Nested Self-Related Objects?

Looks like I need some help here. Salesforce documentation and multiple google searches not gave me an answer.
Problem description:
I'm trying to insert (POST) nested self-related records using REST with JSON, but every time this error appears:
{
"message": "Cannot deserialize instance of <unknown> from FIELD_NAME value records or request may be missing a required field",
"errorCode": "JSON_PARSER_ERROR"
}
JSON:
{
"records" :[{
"attributes" : {"type" : "Test_Obj1__c", "referenceId" : "ref1"},
"name" : "integr parent",
"Test_Obj1__r" : {
"records" : [{
"attributes" : {"type" : "Test_Obj1__c", "referenceId" : "ref2"},
"name" : "integr child"
}]
}
}]
}
Request:
https://mySandboxInstance.com/services/data/v37.0/composite/tree/Test_Obj1__c/
Authorization: OAuth security_token
Content-Type: application/json
So, as you can see Test_Obj1__c is self-related and Child Relationship Name is "Test_Obj1".
I've tested with different self-related objects - it gives same result.
If I'm changing Test_Obj1__r to relation with different child object - it works fine.
Is there any way to insert nested self-related objects through one REST request?