从文档数组中检索零件(Retrieve part from an Array of Document)

编程入门 行业动态 更新时间:2024-10-06 12:27:20
从文档数组中检索零件(Retrieve part from an Array of Document)

我正在使用mongodb和php构建一个项目,所以我的数据库包含以下记录。

{ "_id": { "$id": "515bb7e2a00b2add0b000001" }, "user_id": "user_8888", "events": { "common test I": { "subject": "common test I", "start_date": "04/14/2013", "start_time": "8.00 AM", "end_date": "04/14/2013", "end_time": "10.30 AM", "all_day_event": "false", "discription": "no discription", "location": "STC", "private": "false", "time_zone": "IST", "alarm": "true", "alarm_threshold": "5", "status": "true" } } }

所以只使用查询,我如何从记录中检索“常见测试I”事件。 结果应该是:

{ "subject": "common test I", "start_date": "04/14/2013", "start_time": "8.00 AM", "end_date": "04/14/2013", "end_time": "10.30 AM", "all_day_event": "false", "discription": "no discription", "location": "STC", "private": "false", "time_zone": "IST", "alarm": "true", "alarm_threshold": "5", "status": "true" }

可能吗?

I am building a project using mongodb and php, so my database contains the following record.

{ "_id": { "$id": "515bb7e2a00b2add0b000001" }, "user_id": "user_8888", "events": { "common test I": { "subject": "common test I", "start_date": "04/14/2013", "start_time": "8.00 AM", "end_date": "04/14/2013", "end_time": "10.30 AM", "all_day_event": "false", "discription": "no discription", "location": "STC", "private": "false", "time_zone": "IST", "alarm": "true", "alarm_threshold": "5", "status": "true" } } }

So only using query, how I retrieve "common test I" event from the record. The result should be:

{ "subject": "common test I", "start_date": "04/14/2013", "start_time": "8.00 AM", "end_date": "04/14/2013", "end_time": "10.30 AM", "all_day_event": "false", "discription": "no discription", "location": "STC", "private": "false", "time_zone": "IST", "alarm": "true", "alarm_threshold": "5", "status": "true" }

Is it possible?

最满意答案

db.collection.find({},{"events.common test I":1,_id:0})

db.collection.find({},{"events.common test I":1,_id:0})

更多推荐

本文发布于:2023-08-07 18:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465222.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:零件   组中   文档   Retrieve   Array

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!