得到的MongoDB数组特定元素 [英] Get particular element from mongoDB array

查看:382
本文介绍了得到的MongoDB数组特定元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有蒙戈集合像下面

{
  "auther" : "xyz" , 
  "location" : "zzz" , 
  "books" : 
    [
      {"book1" : "b1" , "date" : 2-3-00} ,
      {"book1" : "b2" , "date" : 4-9-00}
    ]
}

{
  "auther" : "pqr",
  "location" : "zzz" , 
  "books" : 
    [
      {"book1" : "b1" , "date" : 2-4-00}
    ]
}

我想要得到的书B1和作者XYZ的唯一日期。

I want to get the only the date of book b1 and author xyz .

我有做类似下面的查询

db.coll.find({"auther" : "xyz" , "books.book1" : "b1"} , {"books.date" : 1})

但它给人的输出如下:

but it's gives output as follows

"books" : {"date" : 2-4-00} , "books" : {"date" : 4-9-00}

我想要得到的书B1等XYZ .means仅书的唯一日期:{日期:00年2月4日}

在蒙戈有可能还是我做错了什么?

is it possible in mongo or am I doing something wrong?

推荐答案

MongoDB的查询语言的目的是返回所有匹配的文件。

The MongoDB query language is designed to return all matching Documents.

有是只返回子文档的支持。

There is no support for returning only sub-documents.

这问题在MongoDB的车票跟踪的优秀票

This issue has an outstanding ticket in MongoDB's ticket tracker.

更新:它看起来像车票已被标记为固定

UPDATE: it looks like the ticket has been marked as fixed.

请参阅这里如何使用这样的一个例子。

See here for an example of how to use this.

这篇关于得到的MongoDB数组特定元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆