Docs Home / Compass / Customize

Set Default Sort Order设置默认排序顺序

You can specify a default sort order for documents shown in Compass through the Settings panel.您可以通过“设置”面板为Compass中显示的文档指定默认排序顺序。

Note

If you specify a sort order through a query in the Query Bar, the sort order that you specify in the query overrides the default sort order.如果通过查询栏中的查询指定排序顺序,则在查询中指定的排序顺序将覆盖默认排序顺序。

If you save a query, Compass does not save the default sort order as part of the saved query.如果保存查询,Compass不会将默认排序顺序保存为已保存查询的一部分。

About This Task关于此任务

You can choose one of the following default sort options:您可以选择以下默认排序选项之一:

Sort Key排序键Description描述
MongoDB server defaultMongoDB服务器默认值Sort in the natural order of documents按文档的自然顺序排序
_id: 1Sort in ascending order by the _id field_id字段升序排序
_id: -1Sort in descending order by the _id field_id字段降序排序
$natural: -1

Sort in reverse natural order of documents, but ignore existing indexes.按文档的自然逆序排序,但忽略现有索引。

WARNING:警告: Only use this option with development clusters.仅在开发集群中使用此选项。

Note

The default sort option you select does not apply to views or time series collections.您选择的默认排序选项不适用于视图时间序列集合

Procedure过程

1

To open the MongoDB Compass Settings Panel, click the gear icon on the left column of the Compass home screen.要打开MongoDB Compass设置面板,请单击Compass主屏幕左列上的齿轮图标。

Settings gear icon location on MongoDB Compass UI

Alternatively, you can use keyboard shortcuts to open the Settings panel:或者,您可以使用键盘快捷键打开“设置”面板:

  • Windows / Linux: Ctrl + ,
  • Mac: + ,

Compass opens a dialog box where you can configure your MongoDB Compass settings.Compass打开一个对话框,您可以在其中配置MongoDB Compass设置。

2

Open the Default Sort for Query Bar dropdown menu.打开“查询栏的默认排序”下拉菜单。

3

Select the default sort order you would like to use.选择要使用的默认排序顺序。

4

Click Save.单击“保存”。

Note

If you do not specify a default sort order, Compass uses the MongoDB server default sort order of $natural: 1, unless otherwise specified in the Query Bar.如果不指定默认排序顺序,Compass将使用MongoDB服务器默认排序顺序$natural:1,除非在查询栏中另有指定。