MongoDB Compass: How to select Distinct Values of a Field

Rajnesh

I have a MongoDB database where each entry has a 'comment' field. I'm using MongoDB Compass to connect to it, and trying to find all unique values of the 'comment' field. I tried the following code in the 'Aggregations' Tab of Compass (see image below), but I didn't get any result:

{$group: {
  _id: null,
  unique_comments: {
    $addToSet: comment
  }
}

An example of the data, in JSON format, is:

{"name":"Hannah Maxwell","date":"2020-01-07T20:16:13.931629-08:00","comment":"Maybe I like camping","location":{"latitude":43.81710433959961,"longitude":-79.42430114746094,"country":"CA","region":"ON"},"likes":1,"responses":24}
{"name":"Jordan Rodriguez","date":"2019-04-28T20:16:13.931629-07:00","comment":"I hate skiing","location":{"latitude":43.41518783569336,"longitude":-80.51475524902344,"country":"CA","region":"ON"},"likes":5,"responses":1}
{"name":"Bodhi Mckenzie","date":"2019-07-09T20:16:13.931629-07:00","comment":"I think I might like skiing","location":{"latitude":43.65549087524414,"longitude":-79.38555908203125,"country":"CA","region":"ON"},"likes":65,"responses":5}

Image of MongoDB compass Aggregation Tab

mickl

In MongoDB Compass you need to pick the Aggregation Pipeline stage from the menu, try:

enter image description here

The preview data should get displayed on the right-hand side

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

How to sum distinct values of a field in a MongoDB collection (utilizing mongoose)

mongodb. how to select distinct records

How to get distinct values from an array in mongoDB and group them by ID

How to select multiple values in one field?

MongoDB get all distinct values

MYSQL Select two distinct values

Mongodb distinct on a array field with regex query?

Select fields from table with DISTINCT field

MySQL SELECT statment with one DISTINCT field

SELECT DISTINCT query with numeric totals of other field for each distinct

How do I find and update the lowest values for a field in a mongodb query?

How to select DISTINCT using WHERE and OR

How to increment a field in mongodb?

How to select anonymous field?

How to trim values in a field?

MongoDB - Getting distinct values of a column after a group by on another column is applied

How can I select the rest of the row with DISTINCT?

How to find distinct values of multiple columns in Spark

How to count the sum of distinct Excel values in a column?

How to get number of distinct values ? mysql

SQL select distinct values in columns / Dynamic value count in columns

Select distinct values from a column based on highest value in another column

Select rows where top n values of a certain column are distinct

Select records which the values of the field are the same

select a field values that are not found in another table

How to select from table only rows that a value from field 1 are paired with at least two different values of field 2

How to update a field universally in MongoDB?

How to filter field in array in MongoDB

How to order the result from distinct list in MongoDB via Java Driver?

TOP 一覧

  1. 1

    セレンのモデルダイアログからテキストを抽出するにはどうすればよいですか?

  2. 2

    Ansibleで複数行のシェルスクリプトを実行する方法

  3. 3

    tkinterウィンドウを閉じてもPythonプログラムが終了しない

  4. 4

    Windows 10 Pro 1709を1803、1809、または1903に更新しますか?

  5. 5

    Crashlytics:コンパイラー生成とはどういう意味ですか?

  6. 6

    GoDaddyでのCKEditorとKCfinderの画像プレビュー

  7. 7

    パンダは異なる名前の列に追加します

  8. 8

    モーダルダイアログを自動的に閉じる-サーバーコードが完了したら、Googleスプレッドシートのダイアログを閉じます

  9. 9

    グラフ(.PNG)ファイルをエクスポートするZabbix

  10. 10

    Chromeウェブアプリのウェブビューの高さの問題

  11. 11

    ラベルとエントリがpythontkinterに表示されないのはなぜですか?

  12. 12

    Windows 10の起動時間:以前は20秒でしたが、現在は6〜8倍になっています

  13. 13

    mutate_allとifelseを組み合わせるにはどうすればよいですか

  14. 14

    Reactでclsxを使用する方法

  15. 15

    ネットワークグラフで、ネットワークコンポーネントにカーソルを合わせたときに、それらを強調表示するにはどうすればよいですか?

  16. 16

    テキストフィールドの値に基づいて UIslider を移動します

  17. 17

    ファイル内の2つのマーカー間のテキストを、別のファイルのテキストのセクションに置き換えるにはどうすればよいですか?

  18. 18

    MLでのデータ前処理の背後にある直感

  19. 19

    Unity:未知のスクリプトをGameObject(カスタムエディター)に動的にアタッチする方法

  20. 20

    Pythonを使用して同じ列の同じ値の間の時差を取得する方法

  21. 21

    グラフからテーブルに条件付き書式を適用するにはどうすればよいですか?

ホットタグ

アーカイブ