gpt4 book ai didi

mongodb - mongo DB有没有办法获取json数据的内在值?

转载 作者:可可西里 更新时间:2023-11-01 10:30:33 24 4
gpt4 key购买 nike

我的 Json 数据是这样的,(这是我存储在 mongo DB 中的)

/* 0 */
{
"_id" : "e9925559-4830-476f-8d6a-789ade4ec51c",
"account_user_id" : "sahaal",
"account_number" : "23423",
"Job Profile" : {
"externalid" : "250250ICM",
"bgcpackagetype" : [
{
"id" : "C19902",
"value" : "1800 - Happy Path Background Check",
"formattedvalue" : "1800 - Happy Path Background Check"
},
{
"id" : "C19900",
"value" : "2112 - Esteem Validation Package",
"formattedvalue" : "2112 - Esteem Validation Package"
}
],
"links" : [
{
"title" : "The current profile being viewed.",
"rel" : "self",
"url" : "https://api.icims.com/customers/2187/jobs/2015"
}
],
"jobid" : "2013-2015"
},
"request" : {
"newStatus" : "9782",
"oldStatus" : "1752",
"customerId" : "1234",
"jobId" : "1242",
"userId" : "3",
"personId" : "1364",
"links" : [
{
"title" : "Applicant Workflow",
"rel" : "applicantWorkflow",
"url" : "https://api.icims.com/customers/1234/applicantworkflows/2203"
},
{
"title" : "Job Profile",
"rel" : "job",
"url" : "https://api.icims.com/customers/2187/jobs/2015"
},
{
"title" : "Person Profile",
"rel" : "person",
"url" : "https://api.icims.com/customers/2187/people/7260"
},
{
"title" : "Posting User",
"rel" : "user",
"url" : "https://api.icims.com/customers/2187/people/7425"
}
]
},
"Candidate Profile" : {
"workexperience" : [
{
"workdescription" : "Investigated the effects on body weight and bone growth of replacement injections of thyroid hormone and drugs that inhibit thyroid hormone production * Performed IM injections in chickens * Ran 80 blood samples through gas chromatograph to check T1 levels * Prepared bone growth media for 8 sets of experiments",
"entry" : 47964,
"workstartdate" : "2011-01-01",
"workenddate" : "2011-06-01",
"worktitle" : "Research Assistant",
"workemployer" : "UC Riverside"
},
{
"workcity" : "Pomona",
"workdescription" : "Worked closely with staff performing tasks such as escorting patients, preparing charts, stocking rooms with supplies, running errands, answering phones, and light clerical tasks * Provided patient care by taking vital signs, weighing patients, answering call lights and providing psychosocial support for patients * Learned basics of telemetry",
"entry" : 47965,
"workstartdate" : "2009-05-01",
"workcountry" : {
"id" : "D41001",
"value" : "United States",
"abbrev" : "US"
},
"workenddate" : "2011-06-01",
"worktitle" : "Intern",
"workstate" : {
"id" : "D41001008",
"value" : "California",
"abbrev" : "CA"
},
"workemployer" : "Pomona Valley Hospital Medical Center"
}
],
"licensecertification" : [
{
"stateissued" : {
"id" : "D41001008",
"value" : "United States - California",
"formattedvalue" : "United States - California"
},
"entry" : 48064,
"licensecertstatus" : {
"id" : "D37002036001",
"value" : "Current",
"formattedvalue" : "Current"
},
"licensenumber" : "D8257463",
"licensetype" : "Drivers License"
}
],
"email" : "ravi.sathish@fadv.com",
"birthdate" : "1970-01-01",
"lastname" : "Landis",
"links" : [
{
"title" : "The current profile being viewed.",
"rel" : "self",
"url" : "https://api.icims.com/customers/2187/people/7260"
}
],
"firstname" : "Job",
"addresses" : [
{
"addresstype" : {
"id" : "D84002",
"value" : "Home",
"formattedvalue" : "Home"
},
"addresscountry" : {
"id" : "D41001",
"value" : "United States",
"abbrev" : "US"
},
"addresszip" : "92521",
"addressstreet1" : "1234 Street Name",
"entry" : 3403,
"addressstate" : {
"id" : "D41001008",
"value" : "California",
"abbrev" : "CA"
},
"addresscity" : "Riverside"
}
],
"education" : [
{
"degree" : {
"id" : "C19850",
"value" : "B.S",
"formattedvalue" : "B.S"
},
"school" : {
"id" : "C19849",
"value" : "University of California",
"formattedvalue" : "University of California"
},
"entry" : 289,
"major" : {
"id" : "C19852",
"value" : "Biological Sciences",
"formattedvalue" : "Biological Sciences"
}
}
],
"phones" : [
{
"phonetype" : {
"id" : "D83002",
"value" : "Home",
"formattedvalue" : "Home"
},
"phonenumber" : "555-555-5555",
"entry" : 4823
},
{
"phonetype" : {
"id" : "D83003",
"value" : "Fax",
"formattedvalue" : "Fax"
},
"phonenumber" : "666-555-6666",
"entry" : 4829
}
]
},
"account_password" : "Pass12!$",
"Recruiter Profile" : {
"email" : "Harry@fadv.com",
"lastname" : "HiringManager",
"links" : [
{
"title" : "The current profile being viewed.",
"rel" : "self",
"url" : "https://api.icims.com/customers/2187/people/7171"
}
],
"firstname" : "Harry"
}
}

搜索结果应该只显示,

"links" : [ 
{
"title" : "Applicant Workflow",
"rel" : "applicantWorkflow",
"url" : "https://api.icims.com/customers/1234/applicantworkflows/2203"
},
{
"title" : "Job Profile",
"rel" : "job",
"url" : "https://api.icims.com/customers/2187/jobs/2015"
},
{
"title" : "Person Profile",
"rel" : "person",
"url" : "https://api.icims.com/customers/2187/people/7260"
},
{
"title" : "Posting User",
"rel" : "user",
"url" : "https://api.icims.com/customers/2187/people/7425"
}
]

编辑:-

我的需求是,我需要“title”=“Person Profile”的url。因为它可以在任何位置所以我可以说第三个 url

最佳答案

您可以通过点符号获取数组子文档,因此投影 "request.links":1,_id:0

db.collection.find({query},{"request.links":1,_id:0})

应该可以解决问题。


编辑后的问题:

对于编辑后的问题,您需要一个聚合:

db.collection.aggregate( [{$match: {Your document query}},
{$unwind: "$request.links"},
{$match: {"request.links.title":"Person Profile"}},
{$project: {_id : 0, link : "$request.links.url"}}])

逐步解释:

  1. 首先 $match 找到您的文档(与 find 相同)
  2. $unwind 为每个数组元素创建一个文档
  3. 第二个 $match 搜索带有您的标题的链接
  4. $project 只显示链接

关于mongodb - mongo DB有没有办法获取json数据的内在值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26256735/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com