我的 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"}}])
逐步解释:
$match 找到您的文档(与 find 相同)$unwind 为每个数组元素创建一个文档$match 搜索带有您的标题的链接$project 只显示链接关于mongodb - mongo DB有没有办法获取json数据的内在值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26256735/
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/
我有一个奇怪的问题:我在rvm上安装了rubyonrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(
在我的Controller中,我通过以下方式在我的index方法中支持HTML和JSON:respond_todo|format|format.htmlformat.json{renderjson:@user}end在浏览器中拉起它时,它会自然地以HTML呈现。但是,当我对/user资源进行内容类型为application/json的curl调用时(因为它是索引方法),我仍然将HTML作为响应。如何获取JSON作为响应?我还需要说明什么? 最佳答案 您应该将.json附加到请求的url,提供的格式在routes.rb的路径中定义。这
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re
有时我需要处理键/值数据。我不喜欢使用数组,因为它们在大小上没有限制(很容易不小心添加超过2个项目,而且您最终需要稍后验证大小)。此外,0和1的索引变成了魔数(MagicNumber),并且在传达含义方面做得很差(“当我说0时,我的意思是head...”)。散列也不合适,因为可能会不小心添加额外的条目。我写了下面的类来解决这个问题:classPairattr_accessor:head,:taildefinitialize(h,t)@head,@tail=h,tendend它工作得很好并且解决了问题,但我很想知道:Ruby标准库是否已经带有这样一个类? 最佳
大家好!我想知道Ruby中未使用语法ClassName.method_name调用的方法是如何工作的。我头脑中的一些是puts、print、gets、chomp。可以在不使用点运算符的情况下调用这些方法。为什么是这样?他们来自哪里?我怎样才能看到这些方法的完整列表? 最佳答案 Kernel中的所有方法都可用于Object类的所有对象或从Object派生的任何类。您可以使用Kernel.instance_methods列出它们。 关于没有类的Ruby方法?,我们在StackOverflow
我真的为这个而疯狂。我一直在搜索答案并尝试我找到的所有内容,包括相关问题和stackoverflow上的答案,但仍然无法正常工作。我正在使用嵌套资源,但无法使表单正常工作。我总是遇到错误,例如没有路线匹配[PUT]"/galleries/1/photos"表格在这里:/galleries/1/photos/1/edit路线.rbresources:galleriesdoresources:photosendresources:galleriesresources:photos照片Controller.rbdefnew@gallery=Gallery.find(params[:galle
我有一个非常简单的RubyRack服务器,例如:app=Proc.newdo|env|req=Rack::Request.new(env).paramspreq.inspect[200,{'Content-Type'=>'text/plain'},['Somebody']]endRack::Handler::Thin.run(app,:Port=>4001,:threaded=>true)每当我使用JSON对象向服务器发送POSTHTTP请求时:{"session":{"accountId":String,"callId":String,"from":Object,"headers":
我在Rails应用程序中使用CarrierWave/Fog将视频上传到AmazonS3。有没有办法判断上传的进度,让我可以显示上传进度如何? 最佳答案 CarrierWave和Fog本身没有这种功能;你需要一个前端uploader来显示进度。当我不得不解决这个问题时,我使用了jQueryfileupload因为我的堆栈中已经有jQuery。甚至还有apostonCarrierWaveintegration因此您只需按照那里的说明操作即可获得适用于您的应用的进度条。 关于ruby-on-r