Related
I have two collections, a policy collection, and a person collection
The Policy looks something like this:
[{
"_id": {
"$oid": "61169375e2145bbfd73dedbe"
},
"PolicyNumber": {
"Identifier": "A56B096A",
"Sequence": 1
},
"Persons": {
"61169362982ac4e8ae2ad768": null,
"60de07a8dc031e91ac5f35c0": null
},
}]
The Person:
[{
"_id": {
"$oid": "5f0c6d087937e0000145e5c3"
},
"UniqueCode": "PER0004",
"PassportExpiryDate": null,
"Age": 35,
"Gender": "M",
"Nationality": null,
"LanguageCode": null,
"Name": "NAME",
"Surname": "SURNAME",
"Initials": null,
"ContactDetails": {
"Addresses": {
"physicalAddress": {
"AddressType": null,
"UnitNumber": null,
"UnitName": null,
"PoBox": null,
"StreetNumber": null,
"StreetName": null,
"Suburb": null,
"Town": null,
"PostalCode": "7100",
"Country": null,
"Coordinates": null,
"InitialCenter": null
}
},
"EmailAddresses": {
"emailAddress": "EMAIL#EMAIL.COM"
},
"TelephoneNumbers": {
"cellphone": "0000000000"
},
"PreferredCommunicationMethod": "SMS"
},
"BankingDetails": [],
"Statistics": null,
"Imported": false,
"ImportReference": null
}]
I have tried various options with $locate, $let, $convert, etc to enable me to join the two collections on 'Persons' using the Policy collections as the entry point.
I know this is probably fundamentals, but I'm n SQL guy who got dumped with a MongoDB conversion.
Any assistance will be appreciated
this is my data which is available in the database.
INSERT INTO suppliers (id, "createdAt", "updatedAt", "userId", "fullName", email, phone, "profilePicture", "isEnabled", "role", "originDistrict", tln, "companyName", "companyAddress", "assignKam", "assignCluster", "vehicleProvide", "makePayout", "subsType", gender, status, "lookAtBid", "bidAccepted", "activeTrip", "isVerified") VALUES(36, '2022-02-21 18:46:01.527', '2022-09-12 13:20:31.132', '01FRJH5K6GV6KT4YP7RQ4H7N7K', 'syed musa tazim', NULL, '+8801696678835', NULL, false, 'vendor', '{"id": 46, "nameBn": "গাজীপুর", "nameEn": "Gazipur", "status": "active", "createdAt": "2021-12-31T18:08:40.056Z"}'::jsonb, NULL, 'Rofiqul Islam (GZP)', NULL, '{"role": "kam", "team": "vendor_team", "zone": "gazipur", "email": "tauhi15#loopfreight.io", "phone": "+8801721666512", "userId": "01GCDMQ7DS48XTCMT5JBYSS4NF", "fullName": "Mohammad Tareq"}'::jsonb, '{"role": "cluster_head", "zone": "gazipur", "email": "a28#gmail.com", "phone": "+8801328282828", "userId": "01GCNEE49Z3ZCBT73BK2BHVY6P", "fullName": "Iftikar Bhaia Gazipur"}'::jsonb, 20, 'monday'::public."suppliers_makepayout_enum", 'gold'::public."suppliers_substype_enum", 'male'::public."suppliers_gender_enum", 'inactive'::public."suppliers_status_enum", 0, 0, 0, false); INSERT INTO suppliers (id, "createdAt", "updatedAt", "userId", "fullName", email, phone, "profilePicture", "isEnabled", "role", "originDistrict", tln, "companyName", "companyAddress", "assignKam", "assignCluster", "vehicleProvide", "makePayout", "subsType", gender, status, "lookAtBid", "bidAccepted", "activeTrip", "isVerified") VALUES(143, '2022-07-14 10:39:36.397', '2023-01-11 16:03:26.445', '01G7XG2M1X1Y60H3W6GYBR2Q40', 'abcd', 'kamrul.islam#loopfreight.ios', '+8801828378263', NULL, true, 'vendor', '{"id": 46, "nameBn": "গাজীপুর", "nameEn": "Gazipur", "status": "active", "createdAt": "2021-12-31T18:08:40.056Z"}'::jsonb, NULL, 'Transport Agency (GZP)', 'abcd', '{"role": "kam", "team": "vendor_team", "zone": "gazipur", "email": "FoxVTNJ#test.com", "phone": "+8801312121215", "userId": "01GCB9NMCR0FVE7NTE825T06PF", "fullName": "A.B.M. Asaff-Ud-Daula"}'::jsonb, '{"role": "cluster_head", "zone": "gazipur", "email": "a28#gmail.com", "phone": "+8801328282828", "userId": "01GCNEE49Z3ZCBT73BK2BHVY6P", "fullName": "Iftikar Bhaia Gazipur"}'::jsonb, 50, 'wednesday'::public."suppliers_makepayout_enum", 'bronze'::public."suppliers_substype_enum", 'male'::public."suppliers_gender_enum", 'active'::public."suppliers_status_enum", 3, 0, 0, true); INSERT INTO suppliers (id, "createdAt", "updatedAt", "userId", "fullName", email, phone, "profilePicture", "isEnabled", "role", "originDistrict", tln, "companyName", "companyAddress", "assignKam", "assignCluster", "vehicleProvide", "makePayout", "subsType", gender, status, "lookAtBid", "bidAccepted", "activeTrip", "isVerified") VALUES(51, '2022-02-21 18:46:01.527', '2022-10-19 14:17:16.790', '01FV9WW0SZ58C3HX1XV8N6AKSR', 'some vendor 3 update yes', NULL, '+8801711223343', NULL, false, 'vendor', '{"id": 46, "nameBn": "গাজীপুর", "nameEn": "Gazipur", "status": "active", "createdAt": "2021-12-31T18:08:40.056Z"}'::jsonb, NULL, 'Matrichaya Transport Agency (GZP) yes', 'some vendor 3 company address', '{"role": "kam", "team": "vendor_team", "zone": "gazipur", "email": "tauhi15#loopfreight.io", "phone": "+8801721666512", "userId": "01GCDMQ7DS48XTCMT5JBYSS4NF", "fullName": "Mohammad Tareq"}'::jsonb, '{"role": "cluster_head", "zone": "gazipur", "email": "a28#gmail.com", "phone": "+8801328282828", "userId": "01GCNEE49Z3ZCBT73BK2BHVY6P", "fullName": "Bimol Das"}'::jsonb, 200, 'monday'::public."suppliers_makepayout_enum", 'gold'::public."suppliers_substype_enum", 'male'::public."suppliers_gender_enum", 'inactive'::public."suppliers_status_enum", 0, 0, 0, true); INSERT INTO suppliers (id, "createdAt", "updatedAt", "userId", "fullName", email, phone, "profilePicture", "isEnabled", "role", "originDistrict", tln, "companyName", "companyAddress", "assignKam", "assignCluster", "vehicleProvide", "makePayout", "subsType", gender, status, "lookAtBid", "bidAccepted", "activeTrip", "isVerified") VALUES(45, '2022-02-21 18:46:01.527', '2022-10-18 10:13:43.622', '01FSP5XNHEN9WH06Z320YSE416', 'tazim', NULL, '+8801676553344', NULL, false, 'vendor', '{"id": 46, "nameBn": "গাজীপুর", "nameEn": "Gazipur", "status": "active", "createdAt": "2021-12-31T18:08:40.056Z"}'::jsonb, NULL, 'Md. Parvez Alam (GZP)', 'h-747, road-08 ,Adabor ,Dhaka', '{"role": "kam", "team": "vendor_team", "zone": "gazipur", "email": "tauhi15#loopfreight.io", "phone": "+8801721666512", "userId": "01GCDMQ7DS48XTCMT5JBYSS4NF", "fullName": "Mohammad Tareq"}'::jsonb, '{"role": "cluster_head", "zone": "gazipur", "email": "a28#gmail.com", "phone": "+8801328282828", "userId": "01GCNEE49Z3ZCBT73BK2BHVY6P", "fullName": "Iftikar Bhaia Gazipur"}'::jsonb, 12, 'monday'::public."suppliers_makepayout_enum", 'tin'::public."suppliers_substype_enum", 'male'::public."suppliers_gender_enum", 'inactive'::public."suppliers_status_enum", 0, 0, 0, false); INSERT INTO suppliers (id, "createdAt", "updatedAt", "userId", "fullName", email, phone, "profilePicture", "isEnabled", "role", "originDistrict", tln, "companyName", "companyAddress", "assignKam", "assignCluster", "vehicleProvide", "makePayout", "subsType", gender, status, "lookAtBid", "bidAccepted", "activeTrip", "isVerified") VALUES(138, '2022-07-06 13:33:43.305', '2023-01-11 16:33:44.418', '01G796VP5GZWBM90BSXSB5QE6A', 'testing vendor fullname 5', NULL, '+8801345454545', NULL, true, 'vendor', '{"id": 46, "nameBn": "গাজীপুর", "nameEn": "Gazipur", "status": "active", "createdAt": "2021-12-31T18:08:40.056Z"}'::jsonb, NULL, 'Connect Transport Agency (GZP)', 'tesiting vendor address', '{"role": "kam", "team": "vendor_team", "zone": "gazipur", "email": "FoxVTNJ#test.com", "phone": "+8801312121215", "userId": "01GCB9NMCR0FVE7NTE825T06PF", "fullName": "A.B.M. Asaff-Ud-Daula"}'::jsonb, '{"role": "cluster_head", "zone": "gazipur", "email": "a28#gmail.com", "phone": "+8801328282828", "userId": "01GCNEE49Z3ZCBT73BK2BHVY6P", "fullName": "Iftikar Bhaia Gazipur"}'::jsonb, 0, 'wednesday'::public."suppliers_makepayout_enum", 'gold'::public."suppliers_substype_enum", 'male'::public."suppliers_gender_enum", 'active'::public."suppliers_status_enum", 14, 0, 1, true);
I want to replace this
{"role": "cluster_head", "zone": "gazipur", "email": "a28#gmail.com", "phone": "+8801328282828", "userId": "01GCNEE49Z3ZCBT73BK2BHVY6P", "fullName": "Iftikar Bhaia Gazipur"}
with
{userId: '01GBSDPSCAE74FVCK2XPPCRDYH',profilePicture: 'https://dev-cdn.loopfreight.io/public/cd4a89cae5d4516efabf73ccd774583e.jpg',fullName: 'Rayhan Zaman',isEnabled: true,isVerified: true,designation: 'Manager ',department: 'operation',zone: 'khulna',phone: '+8801811111111',email: 'rayhan#gmail.com',createdAt: '2022-08-31T07:44:00.905Z',gender: 'male',role: 'cluster_head'}
how can I change it?
I will get the 2nd json from another service. So I want to replace it.
I have tried like this
update suppliers set "assignCluster" = jsonb_set({userId: '01GBSDPSCAE74FVCK2XPPCRDYH',profilePicture: 'https://dev-cdn.loopfreight.io/public/cd4a89cae5d4516efabf73ccd774583e.jpg',fullName: 'Rayhan Zaman',isEnabled: true,isVerified: true,designation: 'Manager ',department: 'operation',zone: 'khulna',phone: '+8801811111111',email: 'rayhan#gmail.com',createdAt: '2022-08-31T07:44:00.905Z',gender: 'male',role: 'cluster_head'})::jsonb where "assignCluster"->>"userId" = '01GBSDPSCAE74FVCK2XPPCRDYH';
Don't use jsonb_set. You want to replace the entire value of the column, not manipulate some JSON.
Also you need to put the JSON value in an SQL literal, and properly quote property names and strings in it.
update suppliers
set "assignCluster" = '{"userId": "01GBSDPSCAE74FVCK2XPPCRDYH", "profilePicture": "https://dev-cdn.loopfreight.io/public/cd4a89cae5d4516efabf73ccd774583e.jpg", "fullName": "Rayhan Zaman", "isEnabled": true, "isVerified": true, "designation": "Manager", "department": "operation", "zone": "khulna", "phone": "+8801811111111", "email": "rayhan#gmail.com", "createdAt": "2022-08-31T07:44:00.905Z", "gender": "male", "role": "cluster_head"}'
where "assignCluster"->>'userId' = '01GBSDPSCAE74FVCK2XPPCRDYH';
I'm using Mockito in flutter application and want to add some test cases:
this run failed while the actual result is the same as expected result, here's my test file:
#GenerateMocks([ResumeParserDataSource])
void main() {
late MockResumeParserDataSource resumeParserDataSource;
late ResumeParserController resumeParserController;
late ResumeParserRepo resumeParserRepo;
setUp(() async {
Get.reset();
resumeParserDataSource = MockResumeParserDataSource();
resumeParserRepo =
Get.put(ResumeParserRepo(dataSource: resumeParserDataSource));
resumeParserController = Get.put(ResumeParserController());
});
group('Upload resume that uploaded into API:\n', () {
test(
'~succeed state~ api get response and parsed it into model JSON "ParsedDetailsResume"',
() async {
when(resumeParserRepo
.getResumeDetailsAfterParsing(ResumeParserTestUtil.fileName))
.thenAnswer((_) async => Right(
ResumeParserTestUtil.parsedResumeDetailsFunction(
ResumeParserTestUtil.parsedResumeDetailsModel1)));
await resumeParserController
.parseResumeToAPI(ResumeParserTestUtil.fileName);
await waitForAPIResponse();
expect(
resumeParserController.parsedResume.value,
some(ResumeParserTestUtil.parsedResumeDetailsFunction(
ResumeParserTestUtil.parsedResumeDetailsModel1)));
expect(resumeParserController.error.value, none());
});
});
}
here's my ResumeParserController:
class ResumeParserController extends GetxController {
static ResumeParserController get to => Get.find();
final resumeParserRepo = ResumeParserRepo.to;
Rx<Option<ParsedResumeDetails>> parsedResume =
Rx<Option<ParsedResumeDetails>>(none());
Future<Either<DioError, ParsedResumeDetails>> parseResumeToAPI(
String fileName,
{User? user}) async {
var result = await resumeParserRepo.getResumeDetailsAfterParsing(
fileName,
user: user,
);
return result.fold(
(l) => Left(l),
(newParsedResume) async {
error.value = none();
parsedResume.value = some(newParsedResume);
update();
return Right(newParsedResume);
},
);
}
}
and here's my json model in ResumeParserTestUtil:
class ResumeParserTestUtil {
static String fileName = "12989801ahsduiabsdui9123ajd.pdf";
static ParsedResumeDetails parsedResumeDetailsFunction(
Map<String, dynamic> response,
{User? user}) {
var userSkills = response['data']['userSkills'] == null
? [PublicUserSkill.empty()]
: List.from(response['data']['userSkills'])
.map((e) => PublicUserSkill.fromJson(e["skill"]))
.toList();
var userEducations = response['data']['educations'] == null
? [EducationParsed.empty()]
: List.from(response['data']['educations'])
.map((e) => EducationParsed.fromJson(e))
.toList();
var experiences = response['data']['experiences'] == null
? [ExperiencesParsed.empty()]
: List.from(response['data']['experiences'])
.map((e) => ExperiencesParsed.fromJson(e))
.toList();
return ParsedResumeDetails(
user: user,
userSkills:
userSkills.map(mapPublicUserSkillToSkillWithUserSkill).toList(),
userEducation: userEducations,
userWorkExperience: experiences,
);
}
static Map<String, dynamic> parsedResumeDetailsModel1 = {
"data": {
"experiences": [
{
"startDate": null,
"endDate": null,
"isPresent": false,
"organization": "Unnamed company",
"type": "WORK"
}
],
"userSkills": [
{
"skill": {
"id": "7963a547-3980-47d6-8ffc-c9e311152d9b",
"name": "Bachelors Degree > Bachelors Degree Economics",
"popularity": "0",
"flagRecount": false,
"createdAt": null,
"updatedAt": null,
},
},
{
"skill": {
"id": "05516ee5-1706-4296-aaa3-f3386767dec6",
"name":
"Bachelors Degree > Bachelors Degree Information Engineering and Media",
"popularity": "0",
"flagRecount": false,
"createdAt": null,
"updatedAt": null,
}
},
{
"skill": {
"id": "0baaa115-a770-42f5-ad54-291ffa42a11c",
"name": "Bachelors Degree > Bachelors Degree Literature",
"popularity": "0",
"flagRecount": false,
"createdAt": null,
"updatedAt": null
}
},
{
"skill": {
"id": "7a4ca05f-8d75-44c5-b012-5a0298160903",
"name": "Bachelors Degree > Bachelors Degree Mathematics",
"popularity": "0",
"flagRecount": false,
"createdAt": null,
"updatedAt": null,
},
},
{
"skill": {
"id": "b29215d5-c3cf-4b62-82df-2ee5db1c160c",
"name": "Bachelors Degree > Bachelors Degree history",
"popularity": "0",
"flagRecount": false,
"createdAt": null,
"updatedAt": null
}
}
],
"educations": [
{
"startDate": null,
"endDate": null,
"type": "EDUCATION",
"isPresent": true,
"study": {
"id": "572502d1-fb5c-4876-8985-2c4278b98a8b",
"name":
"Information Engineering and Media, history, Economics, Literature, Mathematics",
"createdAt": "",
"updatedAt": ""
},
"school": {
"id": "f54c85dd-f51e-4715-a393-dbcea6edbed7",
"name": "Adamson University",
"domain": "adamson.edu.ph",
"website": "http://www.adamson.edu.ph/",
"state": null,
"type": null,
"CountryCode": "PH",
"createdAt": null,
"updatedAt": null
},
"degree": {
"id": "63dd0edf-9193-4ac0-b693-ae561873e4a3",
"name": "Bachelor",
"createdAt": "",
"updatedAt": ""
}
},
{
"startDate": null,
"endDate": null,
"type": "EDUCATION",
"isPresent": true,
"school": {
"id": "1dedeca8-154b-4e8f-a867-d359616d996c",
"name": "Adipala Junior High School",
"domain": null,
"website": null,
"state": null,
"type": null,
"CountryCode": null,
"createdAt": "",
"updatedAt": null
}
},
{
"startDate": null,
"endDate": null,
"type": "EDUCATION",
"isPresent": true,
"school": {
"id": "38420130-dac4-4a3c-a1bc-cea4777054c1",
"name": "Unnamed school",
"domain": null,
"website": null,
"state": null,
"type": null,
"CountryCode": null,
"createdAt": null,
"updatedAt": null
}
}
]
}
};
}
and this was the result:
Expected: Some:<Some(ParsedResumeDetails([EducationParsed(true, null, null, null, EDUCATION), EducationParsed(true, null, null, null, EDUCATION), EducationParsed(true, null, null, null, EDUCATION)], [ExperiencesParsed(false, null, Unnamed company, null, WORK)], [Instance of 'SkillWithUserSkill', Instance of 'SkillWithUserSkill', Instance of 'SkillWithUserSkill', Instance of 'SkillWithUserSkill', Instance of 'SkillWithUserSkill'], null))>
Actual: Some:<Some(ParsedResumeDetails([EducationParsed(true, null, null, null, EDUCATION), EducationParsed(true, null, null, null, EDUCATION), EducationParsed(true, null, null, null, EDUCATION)], [ExperiencesParsed(false, null, Unnamed company, null, WORK)], [Instance of 'SkillWithUserSkill', Instance of 'SkillWithUserSkill', Instance of 'SkillWithUserSkill', Instance of 'SkillWithUserSkill', Instance of 'SkillWithUserSkill'], null))>
package:test_api
✖ Upload resume that uploaded into API:
~succeed state~ api get response and parsed it into model JSON "ParsedDetailsResume"
Exited (1)
Any thoughts on this? Thanks!
Ran into same issue trying test async call, where it was failing because I set expected value wrapped in a Future.value()
Solution in this case is to :
extract the value from the async call first with await
then do the check on raw value, without any notion of Future<>
eg:
test('test SomeService()', () async {
final actual = await someService.getSomeList();
expect(actual, []);
});
I currently have this collection below, and I need a way to return only one item from an internal array (an item from the "pontosGastronomicos" array), only the object, I don't have much experience with mongodb. I'm developing an application and AngularDart and the backend in Angel, application is already working, I just need an optimized way to do this.
// 1
{
"_id": ObjectId("6025b13eab1951094272d007"),
"id": "03a091e2-fa67-4132-9237-f5b9ed3dbb39",
"dataCadastro": "2021-02-11 19:35:41.998",
"link": null,
"icon": "icon-pizza-1",
"ativo": true,
"order": NumberInt("0"),
...
"pontosGastronomicos": [
{
"id": "208a3f93-9fcb-4db7-ac44-bb11b86a2d31",
"infos": [
{
"id": "925ed160-9276-4046-87a2-d1f37547f7cb",
"title": "BAR DA BOCA",
"lang": "pt",
"content": "Ótima experiência com o melhor chope de Rio das Ostras"
},
{
"id": "abc2ef60-4807-4b16-8d3e-95223abe0524",
"title": "BAR DA BOCA",
"lang": "en",
"content": "Great experience with the best draft beer in Rio das Ostras"
}
],
"midias": [
{
"id": "d54435d2-2fe3-4ea1-aa04-0ccdfade4c9f",
"title": "experimente-praias-1",
"description": "experimente-praias-1.jpg",
"dataCadastro": "2021-02-10 14:23:23.224",
"fisicalFilename": "acd13d50-15af-45fd-98f9-0903d1bb3ea5.jpg",
"originalFilename": "experimente-praias-1.jpg",
"link": "http://localhost:4002/storage/turismo/midias/acd13d50-15af-45fd-98f9-0903d1bb3ea5.jpg",
"mimeType": "image/jpeg",
"tipo": null
}
],
"ativo": true,
"dataCadastro": "2021-02-11 19:51:26.702",
"order": NumberInt("0"),
"link": null,
"email": "bardaboca#yahoo.com.br",
"logradouro": "Rua Teresópolis",
"bairro": "Boca da Barra",
"numero": "69",
"telefone1": "2227641671 ",
"telefone2": "22998578550",
"horarioFuncionamento": "10h as 20h",
"latitude": null,
"longitude": null,
"categoria": null,
"logo": null,
"whatsapp": null,
"tipoDeCozinha": null,
"capacidade": null,
"site": null,
"facebook": null,
"youtube": null,
"instagram": null,
"observacao": null,
}
]
}
I need to make a request that brings me just a "pontosGastronomicos" by id, i currently do this via terminal:
db.pontosGastronomicos.find(
{"pontosGastronomicos.id": "208a3f93-9fcb-4db7-ac44-bb11b86a2d31"},
{_id: 0, pontosGastronomicos: {$elemMatch: {id: "208a3f93-9fcb-4db7-ac44-bb11b86a2d31"}}});
the result is this:
{
"pontosGastronomicos": [
{
"id": "208a3f93-9fcb-4db7-ac44-bb11b86a2d31",
"infos": [
{
"id": "925ed160-9276-4046-87a2-d1f37547f7cb",
"title": "BAR DA BOCA",
"lang": "pt",
"content": "Ótima experiência com o melhor chope de Rio das Ostras"
},
{
"id": "abc2ef60-4807-4b16-8d3e-95223abe0524",
"title": "BAR DA BOCA",
"lang": "en",
"content": "Great experience with the best draft beer in Rio das Ostras"
}
],
"midias": [
{
"id": "d54435d2-2fe3-4ea1-aa04-0ccdfade4c9f",
"title": "experimente-praias-1",
"description": "experimente-praias-1.jpg",
"dataCadastro": "2021-02-10 14:23:23.224",
"fisicalFilename": "acd13d50-15af-45fd-98f9-0903d1bb3ea5.jpg",
"originalFilename": "experimente-praias-1.jpg",
"link": "http://localhost:4002/storage/turismo/midias/acd13d50-15af-45fd-98f9-0903d1bb3ea5.jpg",
"mimeType": "image/jpeg",
"tipo": null
}
],
"ativo": true,
"dataCadastro": "2021-02-11 19:51:26.702",
"order": NumberInt("0"),
"link": null,
"email": "bardaboca#yahoo.com.br",
"logradouro": "Rua Teresópolis",
"bairro": "Boca da Barra",
"numero": "69",
"telefone1": "2227641671 ",
"telefone2": "22998578550",
"horarioFuncionamento": "10h as 20h",
"latitude": null,
"longitude": null,
"categoria": null,
"logo": null,
"whatsapp": null,
"tipoDeCozinha": null,
"capacidade": null,
"site": null,
"facebook": null,
"youtube": null,
"instagram": null,
"observacao": null,
}
]
}
how to return just one object from an array that is inside a collection with the mongo_dart
I would like the result to be like this
{
"id": "208a3f93-9fcb-4db7-ac44-bb11b86a2d31",
"infos": [
{
"id": "925ed160-9276-4046-87a2-d1f37547f7cb",
"title": "BAR DA BOCA",
"lang": "pt",
"content": "Ótima experiência com o melhor chope de Rio das Ostras"
},
{
"id": "abc2ef60-4807-4b16-8d3e-95223abe0524",
"title": "BAR DA BOCA",
"lang": "en",
"content": "Great experience with the best draft beer in Rio das Ostras"
}
],
"midias": [
{
"id": "d54435d2-2fe3-4ea1-aa04-0ccdfade4c9f",
"title": "experimente-praias-1",
"description": "experimente-praias-1.jpg",
"dataCadastro": "2021-02-10 14:23:23.224",
"fisicalFilename": "acd13d50-15af-45fd-98f9-0903d1bb3ea5.jpg",
"originalFilename": "experimente-praias-1.jpg",
"link": "http://localhost:4002/storage/turismo/midias/acd13d50-15af-45fd-98f9-0903d1bb3ea5.jpg",
"mimeType": "image/jpeg",
"tipo": null
}
],
"ativo": true,
"dataCadastro": "2021-02-11 19:51:26.702",
"order": NumberInt("0"),
"link": null,
"email": "bardaboca#yahoo.com.br",
"logradouro": "Rua Teresópolis",
"bairro": "Boca da Barra",
"numero": "69",
"telefone1": "2227641671 ",
"telefone2": "22998578550",
"horarioFuncionamento": "10h as 20h",
"latitude": null,
"longitude": null,
"categoria": null,
"logo": null,
"whatsapp": null,
"tipoDeCozinha": null,
"capacidade": null,
"site": null,
"facebook": null,
"youtube": null,
"instagram": null,
"observacao": null,
}
I get the answer on github, for others who have this difficulty follow the answer:
final cursor = db.collection(collection).modernAggregateCursor([
{
r'$replaceRoot': {
'newRoot': {
r'$arrayElemAt': [
{
r'$filter': {
'input': r'$pontosGastronomicos',
'as': 'pontosGastronomicos',
'cond': {
/* resolve to a boolean value and determine if an element should be included in the output array. */
r'$eq': [r'$$pontosGastronomicos.id', '208a3f93-9fcb-4db7-ac44-bb11b86a2d31']
}
}
},
0 /* the element at the specified array index */
]
}
}
}
]);
result = await cursor.nextObject();
await cursor.close();
/*result = await db.collection(collection).modernFindOne(filter: {
'pontosGastronomicos': {
r'$elemMatch': {'id': '208a3f93-9fcb-4db7-ac44-bb11b86a2d31'}
}
}, projection: {
'_id': 0,
'pontosGastronomicos': {
r'$elemMatch': {'id': '208a3f93-9fcb-4db7-ac44-bb11b86a2d31'}
}
});*/
print(result);
I'm using this URL to get an existing Auto Scale Group that I want to clone with modifications. It seems to have all the informmation about Service Port, Policies, Resource Triggers, Watches, Actions that I need to have.
https://api.softlayer.com/rest/v3/SoftLayer_Scale_Group/1120061/getObject.json?objectMask=mask[policies[resourceUseTriggers[watches],actions],loadBalancers]
The resulting response is contained in "RESPONSE 1" below.
I then modify the response to "remove the IDs" and then modify it to use as a template to create a new Auto Scale Group and the new request JSON is shown in "REQUEST 1" below.
When I submit "REQUEST 1" to SoftLayer using a POST to
https://api.softlayer.com/rest/v3/SoftLayer_Scale_Group/createObject.json
I get the standard error - "The remote server returned an error: (500) Internal Server Error."
So what am I doing incorrectly here?
== REQUEST 1 ==
{ "parameters": [
{
"virtualGuestMemberTemplate": {
"accountId": 940999,
"domain": "partpic.com",
"hostname": "CaffeServer-test-001",
"maxMemory": 1024,
"postInstallScriptUri": "https://webdev.partpic.com/ppsvc/CaffeStartup.aspx?model=Sample.tar.gz",
"startCpus": 1,
"blockDeviceTemplateGroup": {
"globalIdentifier": "fb2fd46d-713a-4d9b-8de1-d47030adc728"
},
"datacenter": {
"name": "dal06"
},
"hourlyBillingFlag": true
},
"loadBalancers": [{
"healthCheckId": 609283,
"id": 101503,
"port": 32400,
"virtualServerId": 275643
}],
"policies": [{
"name": "ScaleDown",
"resourceUseTriggers": [{
"typeId": 3,
"watches": [{
"algorithm": "EWMA",
"metric": "host.cpu.percent",
"operator": "<",
"period": 1500,
"value": "20"
}]
}],
"actions": [{
"typeId": 1,
"amount": 80,
"scaleType": "PERCENT"
}]
},
{
"name": "ScaleUp",
"resourceUseTriggers": [{
"typeId": 3,
"watches": [{
"algorithm": "EWMA",
"metric": "host.cpu.percent",
"operator": ">",
"period": 600,
"value": "80"
}]
}],
"actions": [{
"typeId": 1,
"amount": 150,
"scaleType": "PERCENT"
}]
}],
"status": {
"id": 1,
"keyName": "ACTIVE",
"name": "Active"
},
"virtualGuestAssets": [],
"virtualGuestMembers": [],
"accountId": 940999,
"cooldown": 60,
"name": "scale_test-001",
"regionalGroupId": 22,
"terminationPolicyId": 1
}
]}
== RESPONSE 1 ==
{
"accountId": 940999,
"balancedTerminationFlag": false,
"cooldown": 60,
"createDate": "2016-08-08T13:19:51-05:00",
"desiredMemberCount": null,
"id": 1120061,
"lastActionDate": "2016-08-12T14:22:51-05:00",
"maximumMemberCount": 0,
"minimumMemberCount": 0,
"modifyDate": "2016-08-12T14:22:57-05:00",
"name": "scale_CaffeServerSample",
"regionalGroupId": 22,
"suspendedFlag": false,
"terminationPolicyId": 1,
"virtualGuestMemberTemplate": {
"accountId": 940999,
"createDate": null,
"dedicatedAccountHostOnlyFlag": null,
"domain": "partpic.com",
"hostname": "CaffeServerSample",
"id": null,
"lastPowerStateId": null,
"lastVerifiedDate": null,
"maxCpu": null,
"maxMemory": 1024,
"metricPollDate": null,
"modifyDate": null,
"postInstallScriptUri": "https:\/\/webdev.partpic.com\/ppsvc\/CaffeStartup.aspx?model=Sample.tar.gz",
"provisionDate": null,
"startCpus": 1,
"statusId": null,
"blockDeviceTemplateGroup": {
"accountId": null,
"createDate": null,
"id": null,
"parentId": null,
"publicFlag": null,
"statusId": null,
"transactionId": null,
"userRecordId": null,
"globalIdentifier": "fb2fd46d-713a-4d9b-8de1-d47030adc728"
},
"datacenter": {
"id": null,
"name": "dal06",
"statusId": null
},
"hourlyBillingFlag": true,
"localDiskFlag": false,
"privateNetworkOnlyFlag": false
},
"loadBalancers": [{
"createDate": "2016-08-12T14:06:07-05:00",
"deleteFlag": null,
"healthCheckId": 609283,
"id": 101503,
"modifyDate": "2016-08-12T14:19:33-05:00",
"port": 32400,
"scaleGroupId": 1120061,
"virtualServerId": 274353,
"scaleGroup": {
"accountId": 940999,
"balancedTerminationFlag": false,
"cooldown": 60,
"createDate": "2016-08-08T13:19:51-05:00",
"desiredMemberCount": null,
"id": 1120061,
"lastActionDate": "2016-08-12T14:22:51-05:00",
"maximumMemberCount": 0,
"minimumMemberCount": 0,
"modifyDate": "2016-08-12T14:22:57-05:00",
"name": "scale_CaffeServerSample",
"regionalGroupId": 22,
"suspendedFlag": false,
"terminationPolicyId": 1,
"virtualGuestMemberTemplate": {
"accountId": 940999,
"createDate": null,
"dedicatedAccountHostOnlyFlag": null,
"domain": "partpic.com",
"hostname": "CaffeServerSample",
"id": null,
"lastPowerStateId": null,
"lastVerifiedDate": null,
"maxCpu": null,
"maxMemory": 1024,
"metricPollDate": null,
"modifyDate": null,
"postInstallScriptUri": "https:\/\/webdev.partpic.com\/ppsvc\/CaffeStartup.aspx?model=Sample.tar.gz",
"provisionDate": null,
"startCpus": 1,
"statusId": null,
"blockDeviceTemplateGroup": {
"accountId": null,
"createDate": null,
"id": null,
"parentId": null,
"publicFlag": null,
"statusId": null,
"transactionId": null,
"userRecordId": null,
"globalIdentifier": "fb2fd46d-713a-4d9b-8de1-d47030adc728"
},
"datacenter": {
"id": null,
"name": "dal06",
"statusId": null
},
"hourlyBillingFlag": true,
"localDiskFlag": false,
"privateNetworkOnlyFlag": false
},
"loadBalancers": null,
"policies": [{
"cooldown": null,
"createDate": "2016-08-12T14:23:01-05:00",
"deleteFlag": null,
"id": 174557,
"modifyDate": null,
"name": "ScaleDown",
"scaleGroupId": 1120061,
"actions": [{
"createDate": "2016-08-12T14:23:01-05:00",
"deleteFlag": null,
"id": 166457,
"modifyDate": null,
"scalePolicyId": 174557,
"typeId": 1,
"scalePolicy": null,
"amount": 80,
"scaleType": "PERCENT"
}],
"resourceUseTriggers": [{
"createDate": "2016-08-12T14:23:01-05:00",
"deleteFlag": null,
"id": 173005,
"modifyDate": null,
"scalePolicyId": 174557,
"typeId": 3,
"scalePolicy": null,
"watches": [{
"algorithm": "EWMA",
"createDate": "2016-08-12T14:23:01-05:00",
"deleteFlag": null,
"id": 143505,
"metric": "host.cpu.percent",
"modifyDate": null,
"operator": "<",
"period": 1500,
"scalePolicyTriggerId": 173005,
"value": "20",
"scalePolicyTrigger": null
}]
}],
"scaleGroup": null
},
{
"cooldown": null,
"createDate": "2016-08-12T14:22:51-05:00",
"deleteFlag": null,
"id": 174555,
"modifyDate": null,
"name": "ScaleUp",
"scaleGroupId": 1120061,
"actions": [{
"createDate": "2016-08-12T14:23:01-05:00",
"deleteFlag": null,
"id": 166455,
"modifyDate": null,
"scalePolicyId": 174555,
"typeId": 1,
"scalePolicy": null,
"amount": 150,
"scaleType": "PERCENT"
}],
"resourceUseTriggers": [{
"createDate": "2016-08-12T14:22:51-05:00",
"deleteFlag": null,
"id": 173003,
"modifyDate": null,
"scalePolicyId": 174555,
"typeId": 3,
"scalePolicy": null,
"watches": [{
"algorithm": "EWMA",
"createDate": "2016-08-12T14:22:51-05:00",
"deleteFlag": null,
"id": 143503,
"metric": "host.cpu.percent",
"modifyDate": null,
"operator": ">",
"period": 600,
"scalePolicyTriggerId": 173003,
"value": "80",
"scalePolicyTrigger": null
}]
}],
"scaleGroup": null
}],
"status": {
"id": 1,
"keyName": "ACTIVE",
"name": "Active"
},
"virtualGuestAssets": [],
"virtualGuestMembers": []
}
}],
"policies": [{
"cooldown": null,
"createDate": "2016-08-12T14:23:01-05:00",
"deleteFlag": null,
"id": 174557,
"modifyDate": null,
"name": "ScaleDown",
"scaleGroupId": 1120061,
"actions": [{
"createDate": "2016-08-12T14:23:01-05:00",
"deleteFlag": null,
"id": 166457,
"modifyDate": null,
"scalePolicyId": 174557,
"typeId": 1,
"scalePolicy": null,
"amount": 80,
"scaleType": "PERCENT"
}],
"resourceUseTriggers": [{
"createDate": "2016-08-12T14:23:01-05:00",
"deleteFlag": null,
"id": 173005,
"modifyDate": null,
"scalePolicyId": 174557,
"typeId": 3,
"scalePolicy": null,
"watches": [{
"algorithm": "EWMA",
"createDate": "2016-08-12T14:23:01-05:00",
"deleteFlag": null,
"id": 143505,
"metric": "host.cpu.percent",
"modifyDate": null,
"operator": "<",
"period": 1500,
"scalePolicyTriggerId": 173005,
"value": "20",
"scalePolicyTrigger": null
}]
}],
"scaleGroup": {
"accountId": 940999,
"balancedTerminationFlag": false,
"cooldown": 60,
"createDate": "2016-08-08T13:19:51-05:00",
"desiredMemberCount": null,
"id": 1120061,
"lastActionDate": "2016-08-12T14:22:51-05:00",
"maximumMemberCount": 0,
"minimumMemberCount": 0,
"modifyDate": "2016-08-12T14:22:57-05:00",
"name": "scale_CaffeServerSample",
"regionalGroupId": 22,
"suspendedFlag": false,
"terminationPolicyId": 1,
"virtualGuestMemberTemplate": {
"accountId": 940999,
"createDate": null,
"dedicatedAccountHostOnlyFlag": null,
"domain": "partpic.com",
"hostname": "CaffeServerSample",
"id": null,
"lastPowerStateId": null,
"lastVerifiedDate": null,
"maxCpu": null,
"maxMemory": 1024,
"metricPollDate": null,
"modifyDate": null,
"postInstallScriptUri": "https:\/\/webdev.partpic.com\/ppsvc\/CaffeStartup.aspx?model=Sample.tar.gz",
"provisionDate": null,
"startCpus": 1,
"statusId": null,
"blockDeviceTemplateGroup": {
"accountId": null,
"createDate": null,
"id": null,
"parentId": null,
"publicFlag": null,
"statusId": null,
"transactionId": null,
"userRecordId": null,
"globalIdentifier": "fb2fd46d-713a-4d9b-8de1-d47030adc728"
},
"datacenter": {
"id": null,
"name": "dal06",
"statusId": null
},
"hourlyBillingFlag": true,
"localDiskFlag": false,
"privateNetworkOnlyFlag": false
},
"loadBalancers": [{
"createDate": "2016-08-12T14:06:07-05:00",
"deleteFlag": null,
"healthCheckId": 609283,
"id": 101503,
"modifyDate": "2016-08-12T14:19:33-05:00",
"port": 32400,
"scaleGroupId": 1120061,
"virtualServerId": 274353,
"scaleGroup": null
}],
"policies": null,
"status": {
"id": 1,
"keyName": "ACTIVE",
"name": "Active"
},
"virtualGuestAssets": [],
"virtualGuestMembers": []
}
},
{
"cooldown": null,
"createDate": "2016-08-12T14:22:51-05:00",
"deleteFlag": null,
"id": 174555,
"modifyDate": null,
"name": "ScaleUp",
"scaleGroupId": 1120061,
"actions": [{
"createDate": "2016-08-12T14:23:01-05:00",
"deleteFlag": null,
"id": 166455,
"modifyDate": null,
"scalePolicyId": 174555,
"typeId": 1,
"scalePolicy": null,
"amount": 150,
"scaleType": "PERCENT"
}],
"resourceUseTriggers": [{
"createDate": "2016-08-12T14:22:51-05:00",
"deleteFlag": null,
"id": 173003,
"modifyDate": null,
"scalePolicyId": 174555,
"typeId": 3,
"scalePolicy": null,
"watches": [{
"algorithm": "EWMA",
"createDate": "2016-08-12T14:22:51-05:00",
"deleteFlag": null,
"id": 143503,
"metric": "host.cpu.percent",
"modifyDate": null,
"operator": ">",
"period": 600,
"scalePolicyTriggerId": 173003,
"value": "80",
"scalePolicyTrigger": null
}]
}],
"scaleGroup": {
"accountId": 940999,
"balancedTerminationFlag": false,
"cooldown": 60,
"createDate": "2016-08-08T13:19:51-05:00",
"desiredMemberCount": null,
"id": 1120061,
"lastActionDate": "2016-08-12T14:22:51-05:00",
"maximumMemberCount": 0,
"minimumMemberCount": 0,
"modifyDate": "2016-08-12T14:22:57-05:00",
"name": "scale_CaffeServerSample",
"regionalGroupId": 22,
"suspendedFlag": false,
"terminationPolicyId": 1,
"virtualGuestMemberTemplate": {
"accountId": 940999,
"createDate": null,
"dedicatedAccountHostOnlyFlag": null,
"domain": "partpic.com",
"hostname": "CaffeServerSample",
"id": null,
"lastPowerStateId": null,
"lastVerifiedDate": null,
"maxCpu": null,
"maxMemory": 1024,
"metricPollDate": null,
"modifyDate": null,
"postInstallScriptUri": "https:\/\/webdev.partpic.com\/ppsvc\/CaffeStartup.aspx?model=Sample.tar.gz",
"provisionDate": null,
"startCpus": 1,
"statusId": null,
"blockDeviceTemplateGroup": {
"accountId": null,
"createDate": null,
"id": null,
"parentId": null,
"publicFlag": null,
"statusId": null,
"transactionId": null,
"userRecordId": null,
"globalIdentifier": "fb2fd46d-713a-4d9b-8de1-d47030adc728"
},
"datacenter": {
"id": null,
"name": "dal06",
"statusId": null
},
"hourlyBillingFlag": true,
"localDiskFlag": false,
"privateNetworkOnlyFlag": false
},
"loadBalancers": [{
"createDate": "2016-08-12T14:06:07-05:00",
"deleteFlag": null,
"healthCheckId": 609283,
"id": 101503,
"modifyDate": "2016-08-12T14:19:33-05:00",
"port": 32400,
"scaleGroupId": 1120061,
"virtualServerId": 274353,
"scaleGroup": null
}],
"policies": null,
"status": {
"id": 1,
"keyName": "ACTIVE",
"name": "Active"
},
"virtualGuestAssets": [],
"virtualGuestMembers": []
}
}],
"status": {
"id": 1,
"keyName": "ACTIVE",
"name": "Active"
},
"virtualGuestAssets": [],
"virtualGuestMembers": []
}
I do not think that create a new autoscale group is so easy like copy paste and delete some ids.
try this request:
{
"parameters": [
{
"balancedTerminationFlag": false,
"maximumMemberCount": 0,
"minimumMemberCount": 0,
"cooldown": 60,
"name": "scale_test-0012a",
"regionalGroupId": 22,
"suspendedFlag": false,
"terminationPolicyId": 1,
"virtualGuestMemberTemplate": {
"domain": "partpic.com",
"hostname": "CaffeServer-test-001",
"maxMemory": 1024,
"postInstallScriptUri": "https://webdev.partpic.com/ppsvc/CaffeStartup.aspx?model=Sample.tar.gz",
"startCpus": 1,
"blockDeviceTemplateGroup": {
"globalIdentifier": "fb2fd46d-713a-4d9b-8de1-d47030adc728"
},
"datacenter": {
"name": "dal06"
},
"hourlyBillingFlag": true,
"localDiskFlag": false,
"privateNetworkOnlyFlag": false
},
"loadBalancers": [{
"deleteFlag" : false,
"port": 32400,
"virtualServerId": 275643,
"healthCheck": {
"type": {
"keyname": "DEFAULT"
}
}
}],
"policies": [{
"name": "ScaleDown",
"resourceUseTriggers": [{
"watches": [{
"algorithm": "EWMA",
"metric": "host.cpu.percent",
"operator": "<",
"period": 1500,
"value": "20"
}]
}],
"scaleActions": [{
"amount": 80,
"scaleType": "PERCENT"
}]
}, {
"name": "ScaleUp",
"resourceUseTriggers": [{
"typeId": 3,
"watches": [{
"algorithm": "EWMA",
"metric": "host.cpu.percent",
"operator": ">",
"period": 600,
"value": "80"
}]
}],
"scaleActions": [{
"amount": 150,
"scaleType": "PERCENT"
}]
}]
}
]
}