簡體   English   中英

MongoDB find()僅從集合中檢索一個屬性

[英]MongoDB find() which is retrieving only one property from the collection

我有一個博客帖子集合,其中記錄的結構為{title,author,contents},我想檢索我正在執行的所有作者的所有姓名:

this.db.collection("ContentText").find("authors");

但是我的輸出是undefined有人可以指出錯誤嗎?

嘗試這個:

this.db.collection("ContentText").distinct("author");

嘗試這個:

this.db.collection('<collection_name>').find(<queryObject>,{author:1});

該查詢將返回帶有_id的作者數組,您可以通過以下方式排除_id

{_id:0,author:1}

欲了解更多,請閱讀

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM