var getallskills = document.getElementById('OpenJobs').value;
var preselectedCategories = getallskills.split(",");
var getallskills2 = document.getElementById('HiddenField1').value;
var preselectedCategories2 = getallskills2.split(",");
var geter = "Filled";
var pregeter = geter.split(",");
var search = instantsearch({
appId: 'XXXXXXXXX',
apiKey: 'XXXXXXXXXXXX',
indexName: 'Jobs',
searchParameters: {
"disjunctiveFacetsRefinements": {
"JobTitle": preselectedCategories
},
"facetsExcludes": {
"Emails.User": preselectedCategories2,
"Status": pregeter
}
}});
I am trying to get disjunctiveFacetsRefinements working with facetsExcludes and it doesn't seem to work. Is there something I am doing wrong? Perhaps a bug?
I figured this out..... I think the problem is the disjunctiveFacetsRefinements. If you look you at my code:
"disjunctiveFacetsRefinements": {
//Facet Following Users
"JobTitle": preselectedCategories//, "ToUser.EmailAddress": emailaddress
},
So what it does is it only looks at the "JobTitle" facet. So it limits my results. Is there a way where I can change the searchParameter to have a LIKE type query looking at searchable fields?
Related
I'm a new developer, I want to add an assignment in Google Classroom using a script. Here is the code that was created:
function assignmentWithDriveFile(){
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName('ASSIGNMENT (Drive File)');
const courseId = sheet.getRange('B1').getValue();
const topicId = sheet.getRange('B2').getValue.toString();
var assignment = {
topicId: topicId,
title: sheet.getRange('B3').getValue().toString(),
description: sheet.getRange('B4').getValue().toString(),
materials :[{
driveFile: {
driveFile: {
id: sheet.getRange('B5').getValue.toString(),
title: sheet.getRange('B6').getValue.toString()
},
shareMode: "STUDENT_COPY"
}
}],
maxPoints : sheet.getRange('B7').getValue().toString(),
state: "PUBLISHED",
workType: "ASSIGNMENT"
};
const newCourseAssignment = Classroom.Courses.CourseWork.create(assignment, courseId);
const assId = newCourseAssignment.id;
sheet.getRange('D1').setValue(assId);
}
after running I get a notification in my spreadsheet that is "GoogleJsonResponseException: API call to classroom.courses.courseWork.create failed with error: #AttachmentNotVisible The item referenced by an attachment was not found or not visible to the user."
well what should i do?
I really wait for your answer and I appreciate it```
Do I have to change the drive ID?
Modification points:
About the error of The item referenced by an attachment was not found or not visible to the user., in this case, when the file ID is the invalid file ID, such an error occurs. When I saw your showing script, I thought that at id: sheet.getRange('B5').getValue.toString(),, getValue should be getValue(). This can be also seen at title: sheet.getRange('B6').getValue.toString(). If your file ID is correct, I thought that the reason for your issue might be due to this.
In your situation, I think that the values can be retrieved from cells B1:B7 by one call.
When these points are reflected in your script, how about the following modification?
Modified script:
function assignmentWithDriveFile() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName('ASSIGNMENT (Drive File)');
const [[courseId], [topicId], [title], [description], [driveFileId], [driveFileTitle], [maxPoints]] = sheet.getRange("B1:B7").getDisplayValues();
var assignment = {
topicId,
title,
description,
materials: [{
driveFile: {
driveFile: {
id: driveFileId, title: driveFileTitle
},
shareMode: "STUDENT_COPY"
}
}],
maxPoints: maxPoints,
state: "PUBLISHED",
workType: "ASSIGNMENT"
};
const newCourseAssignment = Classroom.Courses.CourseWork.create(assignment, courseId);
const assId = newCourseAssignment.id;
sheet.getRange('D1').setValue(assId);
}
I think that when these values of [[courseId], [topicId], [title], [description], [driveFileId], [driveFileTitle], [maxPoints]] are correct values, this script works.
We are looking for ways to bulk upload data into google firestore and found here in Stack Overflow an awesome script to do so, sort of. The problem is that when data is uploaded the collection is fine, document is fine, but nesting some data we can only manage to import as "map" type when we need "array" and "map". Since we are basically newbies trial and error has not been enough. We appreciate if you can take a look at the code and help us with that.
So far, with the following code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://www.gstatic.com/firebasejs/7.5.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.5.0/firebase-firestore.js"></script>
</head>
<body>
<script>
var config = {
apiKey: 'MY API KEY',
authDomain: 'MY AUTHDOMAIN',
projectId: 'MY PROJECT ID'
};
firebase.initializeApp(config);
var firestore = firebase.firestore();
//Paste from the CSV to JSON converter
const data = [
{
"collection": "sub_cats",
"uid": "Av9vJ0EoFfxhAR2",
"class": "especialidades_medicas",
"id": 0,
"name": "Cardiologo",
"ind": "11",
"district": ""
},
{
"collection": "sub_cats",
"uid": "Av9vJ0EoFfxhAR2",
"class": "especialidades_medicas",
"id": 1,
"name": "Urologo",
"ind": "12",
"district": ""
}
]
var promises = [];
data.forEach(function (arrayItem) {
var docRef = firestore.collection(arrayItem.collection).doc(arrayItem.uid);
var objClass = {};
var objId = {};
objId[arrayItem.id] = { name: arrayItem.name, ind: arrayItem.ind };
objClass[arrayItem.class] = objId;
promises.push(docRef.set(objClass, { merge: true }));
});
</script>
</body>
</html>
we get this:
data structure current / needed
How would you modify this code to get the array / map structure?
Thanks a lot!!!
You will need to use arrayUnion() of fieldValue that can be used with set() or update(). So basically if you use it with update it will "merge" the new value with the existing array values in your document. Inside that you can have your map or any datatype you want.
An example code looks like this:
db.collection("users").doc(props.uid).update({
points: db.FieldValue.arrayUnion({value: pointObj.value, reason: pointObj.reason})
});
I've got such User object:
{
"_id": "584d91ff6c751769fab91be5",
"username": "svit",
"name": "Ilya",
"role": "user",
"authData": [
{
"fb": {
"access_token": "susdfg",
"expiration_date": 1,
"id": "1187410264678321"
}
}
],
"__v": 9,
"currentToken": "9735f44f1c4371f143747ff670b0076148053f391ab866bafab7c6eaf47d295b"
}
I am interested in updating User.authData.fb. I tried that:
var curUser = userModel.findOne({_id: user._id}, function(err, curUser){
curUser['authData'][socialType] = {
access_token: socialToken,
expiration_date: 173249700 //TODO: normal date
};
curUser.set('currentToken', tokenName);
curUser.markModified('authData');
curUser.save();
});
But that does just nothing. It modifies currentToken, but not authData.
Also, I tried curUser.set('authData.fb.expiration_date", 173249700)
That does not works too.
I really need your help!
Best regards,
Ilya
You can loop through the 'authData' array and modify whatever values you may like. I am assuming authData is a array of socialTypes and it has an attribute name to indentify.
example:
var curUser = userModel.findOne({_id: user._id}, function(err, curUser){
curUser.authData.map(socialType => {
// Select the type of socialAuth you want to modify
if(socialType.name === 'fb') {
access_token: socialToken,
expiration_date: 173249700 //TODO: normal date
}
})
curUser.set('currentToken', tokenName);
curUser.markModified('authData');
curUser.save();
});
I've got the following document named "clients" which includes id, name and list of projects (array of objects):
{
"_id": {
"$oid": "572225d997bb651819f379f7"
},
"name": "ppg",
"projects": [
{
"name": "aaa",
"job_description": "",
"projectID": 20
},
{
"name": "bbbb",
"job_description": "",
"projectID": 21
}
]
}
I would like to update "job_description" of project with given "projectID" like this:
module.exports.saveJobDesc = function(client, idOfProject, textProvided) {
db.clients.update({ name: client},
{ $set: {'projects.0.job_description': textProvided }});
};
But instead of hardcoded index "0" of array I want to find specific project using "projectID". Is there a way to achieve this without changing the structure of collection and/or document?
If you want to update the "job_description" where name="ppg" and project_id=20 then you can use below mongo query:-
db.clients.update({ "name":"ppg","projects.projectID":20 },{$set: {"projects.$.job_description": "abcd"}})
Please let me know if any thing else is required
You cannot update multiple array elements in single update operation, instead you can update one by one which takes time depends upon number of elements in array and number of such documents in collection. see New operator to update all matching items in an array
db.test2.find().forEach( function(doc) {
var projects = doc.projects;
for(var i=0;i<projects.length;i++){
var project = projects[i];
if(project.projectID == 20){
var field = "projects."+i+".job_description";
var query = {};
query[field] = "textasdsd";
db.test2.update({ _id: doc._id},{ $set:query});
}
}
})
Given the following setup code (loosely realistic)
default.js (used by config.js for loading base configurations)
{
"templateData": {
"corp": {
"corpName": "Company",
"DepartmentOne": {
"name": "DepartmentOne",
"phone": "1-800-555-555",
"email": "departmentone#company.com"
},
"address": {
"main": {
"addressLine1": "Somwhere",
"city": "SomeTown",
"stateShort": "SState",
"stateLong": "SomeState",
"zipCodeShort": "Zippy"
}
},
"urls": {
"company": {
"corporate": {
"site": "https://company.com/",
"logo": "http://sites.company.com/images/logo.png",
"altText" : "Company Corporate Logo"
},
"facebook": {
"site": "https://www.facebook.com/company",
"icon": "http://sites.company.com/images/facebook.png",
"altText" : "Company Facebook Page"
},
"twitter": {
"site": "https://twitter.com/company",
"icon": "http://sites.company.com/images/twitter.png",
"altText" : "Company Twitter Feed"
},
"youtube": {
"site": "https://www.youtube.com/company",
"icon": "http://sites.company.com/images/youtube.png",
"altText" : "Company YouTube Channel"
}
}
},
"currentYear": "2015",
"corpWebSiteName": "Company.com"
}
}
}
test01.js (main node code)
var fs = require('fs');
var bunyan = require('bunyan');
var jade = require('jade');
var config = require('config');
var restify = require('restify');
var log = bunyan.createLogger({src: false, name: "emailTemplateMerger"});
var html = '';
var corpConfig = config.get('templateData');
var emailData = { 'emailAddress' : 'nonya#bidness.com',
'firstName' : 'nonya',
'lastName' : 'bidness'
}
var miscData = { 'billingDate' : '2015-08-01',
'accountType' : 'new',
'discountTypes' : {
'primary' : 'Coupon20',
'bonus' : 'First30Days',
'standard' : 'freeShipping'
}
}
fs.readFile('./emailTemplates/test01.jade', 'utf-8', function(error, source){
var template = jade.compile(source);
html = template(corpConfig)
console.log(html);
});
Jade Template:
html
head
body
p.
Hello #{emailData.firstName},
p.
Welcome to #{corp.corpName}'s #{DepartmentOne.name}.
p.
Your next bill will be sent on #{miscData.billingDate} for your #{miscData.accountType}.
p.
Thank you
Problem: Determining an efficient method of merging the config data and the 2 local datasets (which will be passed in via REST) into the Jade template.
Since the data has many levels of nesting, a direct merge can be complex and possibly error prone depending on the data passed in, is there anyway to pass Jade multiple, separate datasets and defer the merging to the Jade engine?
I've tried multiple passes, but a single pass of the Jade merge removes all tags from the template so that didn't work out. I haven't figured out anyway to chain the results.
You could create a top level context object like this:
var context = {
corp: corpConfig,
email: emailData,
misc: miscData
};
....
var html = template(context);
And then change the template references to something like this
html
head
body
p.
Hello #{context.email.firstName},
p.
Welcome to #{context.corp.corpName}'s #{context.misc.DepartmentOne.name}.