如何在couchdb中从两个json文档中找到匹配的数据
How to find matching datas from two json documents in couchdb?
如何从两个json文档中找到匹配的数据。例如:我有两个json文档和skill-json文档。
技能文档:
{
"_id": "b013dcf12d1f7d333467b1447a00013a",
"_rev": "3-e54ad6a14046f809e6da872294939f12",
"core_skills": [
{
"core_skill_code": "SA1",
"core_skill_desc": "communicate with others in writing"
},
{
"core_skill_code": "SA2",
"core_skill_desc": "complete accurate well written work with attention to detail"
},
{
"core_skill_code": "SA3",
"core_skill_desc": "follow guidelines/procedures/rules and service level agreements"
},
{
"core_skill_code": "SA4",
"core_skill_desc": "ask for clarification and advice from others"
}
]}
在员工文档中:
{
"_id": "b013dcf12d1f7d333467b12350007op",
"_rev": "3-e54ad6a14046f809e6da156794939f12",
"employee_name" :"Ashwin",
"employee_role" : "Software engineer",
"core_skills":["SA1","SA4"]
}
我不知道你想做什么,但以下内容可能会有所帮助。假设第一个数据集是技能及其描述的列表,第二个是员工记录,那么为具有合适名称的变量赋值可能看起来像:
var skillCodes = {
"_id": "b013dcf12d1f7d333467b1447a00013a",
"_rev": "3-e54ad6a14046f809e6da872294939f12",
"core_skills": [{
"core_skill_code": "SA1",
"core_skill_desc": "communicate with others in writing"
},{
"core_skill_code": "SA2",
"core_skill_desc": "complete accurate well written work with attention to detail"
},{
"core_skill_code": "SA3",
"core_skill_desc": "follow guidelines/procedures/rules and service level agreements"
},{
"core_skill_code": "SA4",
"core_skill_desc": "ask for clarification and advice from others"
}
]};
var employee0 = {
"_id": "b013dcf12d1f7d333467b12350007op",
"_rev": "3-e54ad6a14046f809e6da156794939f12",
"employee_name" :"Ashwin",
"employee_role" : "Software engineer",
"core_skills":["SA1","SA4"]
};
创建技能索引可以让寻找特定技能变得更简单,一些代码可以做到这一点:
var skillCodeIndex = {};
skillCodes.core_skills.forEach(function(item){
skillCodeIndex[item.core_skill_code] = item.core_skill_desc;
});
现在所需要的只是获得特定员工技能的功能,比如:
function getCoreSkills (employee) {
console.log('Employee ' + employee.employee_name + ' has the following core skills:');
employee.core_skills.forEach(function(skill) {
console.log(skill + ': ' + skillCodeIndex[skill]);
});
}
一个例子:
getCoreSkills(employee0);
Employee Ashwin has the following core skills:
SA1: communicate with others in writing
SA4: ask for clarification and advice from others
对于skillCodes和employee实例的构造函数,以上内容可能会变得更加面向对象,我将留给您。
相关文章:
- 如何使用猫鼬将常规 JSON 对象转换为 Mongo 文档
- 从 JSON 对象数组中获取与条件匹配的文档
- 将json作为子文档合并到另一个json中
- 如何在数据驱动文档中创建动态 json 并在 jsp 中获取 json 响应
- 如何将对象数组转换为单个 JSON 文档/对象
- 从 html 文档中提取 json var
- 从文档正文分析 Json
- 将元素添加到 JSON 文档
- 通过Javascript中的JSON文档数组&使用KnockoutJS的JQuery
- 使用MongoDB查询JSON中的嵌套文档
- 如何在couchdb中从两个json文档中找到匹配的数据
- 需要使用此JSON文档并使用$.ajax()从API创建每小时一次的天气更新
- Node.js:在迭代的JSON POST数据上创建多个MongoDB文档
- Html/Javascript-如何从窗口/文档(Solr)中获取JSON/XML内容
- 如何从JSON文档数组中提取字段数组
- 无法通过mandrillapp JSON api将文档附加到电子邮件
- 在jQuery文档中解析JSON
- 超链接在新的文档窗口中返回JSON.我希望它回到一个变量,比如response"
- 资源被解释为文档,但以MIME类型application/json传输
- 为什么我看不到新插入的JSON文档?