Запрос для получения значений для определенного ключа в MongoDB - PullRequest
0 голосов
/ 07 мая 2019

У меня есть коллекция, которая содержит записи в следующем формате.

{
"_id" : 21,
"title" : "3D User Interfaces with Java 3D",
"isbn" : "1884777902",
"pageCount" : 520,
"publishedDate" : ISODate("2000-08-01T07:00:00Z"),
"thumbnailUrl" : "https://s3.amazonaws.com/AKIAJC5RLADLUMVRPFDQ.book-thumb-images/barrilleaux.jpg",
"longDescription" : "3D User Interfaces with Java 3D is a practical guide for providing next-generation applications with 3D user interfaces for manipulation of in-scene objects. Emphasis is on standalone and web-based business applications, such as for online sales and mass customization, but much of what this book offers has broad applicability to 3D user interfaces in other pursuits such as scientific visualization and gaming.  This book provides an extensive conceptual framework for 3D user interface techniques, and an in-depth introduction to user interface support in the Java 3D API, including such topics as picking, collision, and drag-and-drop. Many of the techniques are demonstrated in a Java 3D software framework included with the book, which also provides developers with many general-purpose building blocks for constructing their own user interfaces.    Applications and their use of 3D are approached realistically. The book is geared towards sophisticated user interfaces for the \"everyday user\" who doesn't have a lot of time to learn another application--much less a complicated one--and an everyday computer system without exotic devices like head mounted displays and data gloves. Perhaps the best description of this book is: \"A roadmap from Java 3D to 'Swing 3D'.\"",
"status" : "PUBLISH",
"authors" : [
    "Jon Barrilleaux"
],
"categories" : [
    "Java",
    "Computer Graphics"
]

}

Я хочу извлечь все значения заголовков из коллекции.

Я пытался использовать что-то вроде:

db.<Collection_name>.find(title)

Но он возвращает ошибку как ReferenceError: заголовок не определен.

Не могли бы вы дать свои предложениясделать эту работу.

1 Ответ

1 голос
/ 07 мая 2019

.find () методы принимают два аргумента: первый - для запроса (вы можете передать пустой объект), а второй - для проекции (какие поля должны быть возвращены), поэтому ваш запрос должен выглядеть так::

db.<Collection_name>.find({}, { title: 1 })
...