Hướng dẫn get collection mongodb - nhận mongodb bộ sưu tập

Tài liệu về nhà → Hướng dẫn sử dụng MongoDBMongoDB Manual

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

1 return một mảng các tài liệu với thông tin thu thập hoặc xem, chẳng hạn như tên và tùy chọn, cho cơ sở dữ liệu hiện tại. Kết quả phụ thuộc vào đặc quyền của người dùng. Để biết chi tiết, xem truy cập cần thiết.
Hướng dẫn get collection mongodb - nhận mongodb bộ sưu tập

Returns an array of documents with collection or view information, such as name and options, for the current database. The results depend on the user's privilege. For details, see Required Access.

Người trợ giúp

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

2 kết thúc lệnh

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

3.

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

2
helper wraps the

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

3 command.

Phương thức

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

2 có tham số tùy chọn sau:

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

2
method has the following optional parameter:

Tham số

Loại hình

Sự mô tả

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

5

tài liệu

Không bắt buộc. Một biểu thức truy vấn để lọc danh sách các bộ sưu tập.

Bạn có thể chỉ định biểu thức truy vấn trên bất kỳ trường nào được trả về bởi

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

2

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

2

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

7

boolean

Không bắt buộc. Một cờ để cho biết liệu lệnh có chỉ trả về chỉ tên/xem tên và nhập hoặc trả về cả tên và thông tin khác hay không.

Chỉ trả lại tên và loại (

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

8 hoặc

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

9) không lấy khóa cấp bộ sưu tập trong khi trả về thông tin thu thập đầy đủ khóa mỗi bộ sưu tập trong cơ sở dữ liệu.

Giá trị mặc định là

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

0.

Ghi chú

Khi

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

7 là

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

2, biểu thức

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

5 của bạn chỉ có thể lọc dựa trên tên và loại của bộ sưu tập. Không có trường khác có sẵn.

Mới trong phiên bản 4.0.

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

4

boolean

Không bắt buộc. Một lá cờ, khi được đặt thành

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

2 và được sử dụng với

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

6, cho phép người dùng không có đặc quyền cần thiết (nghĩa là hành động

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

3 trên cơ sở dữ liệu) để chạy lệnh khi được thực thi kiểm soát truy cập.

Khi cả hai tùy chọn

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

4 và

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

7 được đặt thành TRUE, lệnh chỉ trả về các bộ sưu tập mà người dùng có đặc quyền. Ví dụ: nếu người dùng có hành động
db.runCommand( { listCollections: 1.0, authorizedCollections: true } )
db.runCommand( { listCollections: 1.0, nameOnly: true } )
0 trên các bộ sưu tập cụ thể, lệnh chỉ trả về các bộ sưu tập đó; Hoặc, nếu người dùng có
db.runCommand( { listCollections: 1.0, authorizedCollections: true } )
db.runCommand( { listCollections: 1.0, nameOnly: true } )
0 hoặc bất kỳ hành động nào khác, trên tài nguyên cơ sở dữ liệu, lệnh liệt kê tất cả các bộ sưu tập trong cơ sở dữ liệu.

Giá trị mặc định là

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

0. Nghĩa là, người dùng phải có hành động

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

3 trên cơ sở dữ liệu để chạy lệnh.

Đối với người dùng có hành động

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

3 trên cơ sở dữ liệu, tùy chọn này không có hiệu lực vì người dùng có đặc quyền liệt kê các bộ sưu tập trong cơ sở dữ liệu.

Khi được sử dụng mà không có

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

6, tùy chọn này không có hiệu lực. Nghĩa là, người dùng phải có các đặc quyền cần thiết để chạy lệnh khi kiểm soát truy cập được thực thi. Mặt khác, người dùng được phép chạy lệnh.

Mới trong phiên bản 4.0.

Đã thay đổi trong phiên bản 3.2.

MongoDB 3.2 đã thêm hỗ trợ để xác thực tài liệu.

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

2 bao gồm thông tin xác nhận tài liệu trong tài liệu
db.runCommand( { listCollections: 1.0, authorizedCollections: true } )
db.runCommand( { listCollections: 1.0, nameOnly: true } )
7.

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

2
includes document validation information in the
db.runCommand( { listCollections: 1.0, authorizedCollections: true } )
db.runCommand( { listCollections: 1.0, nameOnly: true } )
7 document.

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

2 không trả lại
db.runCommand( { listCollections: 1.0, authorizedCollections: true } )
db.runCommand( { listCollections: 1.0, nameOnly: true } )
9 và

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

0 trừ khi chúng được đặt rõ ràng. does not return
db.runCommand( { listCollections: 1.0, authorizedCollections: true } )
db.runCommand( { listCollections: 1.0, nameOnly: true } )
9 and

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

0 unless they are explicitly set.

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

2 là một trình bao bọc xung quanh

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

3, người dùng phải có các đặc quyền giống như

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

3 khi kiểm soát truy cập được thực thi.

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

2
is a wrapper around the

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

3, users must have the same privileges as

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

3 when access control is enforced.

Để chạy

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

3 Khi kiểm soát truy cập được thực thi, nói chung, người dùng phải có các đặc quyền cấp hành động

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

3 trên cơ sở dữ liệu. Ví dụ: đặc quyền sau đây cấp cho người dùng chạy

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

2 so với cơ sở dữ liệu

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

7:

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

2
against the

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

7 database:

{ resource: { db: "test", collection: "" }, actions: [ "listCollections" ] }

Vai trò tích hợp

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

8 cung cấp đặc quyền để chạy

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

3 cho một cơ sở dữ liệu cụ thể.

Tuy nhiên, bắt đầu trong phiên bản 4.0, người dùng không có đặc quyền cần thiết có thể chạy lệnh với cả hai tùy chọn

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

4 và

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

7 được đặt thành

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

2. Trong trường hợp này, lệnh chỉ trả về tên và loại của (các) bộ sưu tập mà người dùng có đặc quyền.both

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

4 and

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

7 options set to

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

2. In this case, the command returns just the name and type of the collection(s) to which the user has privileges.

Ví dụ: xem xét người dùng có vai trò chỉ cấp đặc quyền sau:

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

Người dùng có thể chạy lệnh nếu lệnh bao gồm cả tùy chọn

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

4 và

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

7 được đặt thành

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

2 (có hoặc không có tùy chọn

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

5):both

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

4 and

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

7 options set to

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

2 (with or without the

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

5 option):

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

Hoạt động trả về tên và loại của bộ sưu tập

use example
db.getCollectionInfos()
7.

Tuy nhiên, lỗi hoạt động sau (có hoặc không có tùy chọn

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

5) cho người dùng mà không có quyền truy cập cần thiết:

db.runCommand( { listCollections: 1.0, authorizedCollections: true } )
db.runCommand( { listCollections: 1.0, nameOnly: true } )

Bắt đầu từ phiên bản 4.0 của shell

use example
db.getCollectionInfos()
9,
[
{
"name" : "employees",
"type" : "collection",
"options" : {
"flags" : 1,
"validator" : {
"$or" : [
{
"phone" : {
"$exists" : true
}
},
{
"email" : {
"$exists" : true
}
}
]
}
},
"info" : {
"readOnly" : false,
"uuid" : UUID("222e18ca-4a10-4a42-a8fe-c39255cc4c55")
},
"idIndex" : {
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "example.employees"
}
},
{
"name" : "products",
"type" : "collection",
"options" : {
"flags" : 1
},
"info" : {
"readOnly" : false,
"uuid" : UUID("1bc898b2-3b91-45e4-9d8b-0be462d5a157")
},
"idIndex" : {
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "example.products"
}
},
{
"name" : "mylogs",
"type" : "collection",
"options" : {
"capped" : true,
"size" : 256
},
"info" : {
"readOnly" : true,
"uuid" : UUID("8e62116d-b6a0-490a-808c-258ccb7ea947")
},
"idIndex" : {
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "example.mylogs"
}
}
]
0 tương đương với:

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

  • Đối với người dùng có quyền truy cập cần thiết,

    [
    {
    "name" : "employees",
    "type" : "collection",
    "options" : {
    "flags" : 1,
    "validator" : {
    "$or" : [
    {
    "phone" : {
    "$exists" : true
    }
    },
    {
    "email" : {
    "$exists" : true
    }
    }
    ]
    }
    },
    "info" : {
    "readOnly" : false,
    "uuid" : UUID("222e18ca-4a10-4a42-a8fe-c39255cc4c55")
    },
    "idIndex" : {
    "v" : 2,
    "key" : {
    "_id" : 1
    },
    "name" : "_id_",
    "ns" : "example.employees"
    }
    },
    {
    "name" : "products",
    "type" : "collection",
    "options" : {
    "flags" : 1
    },
    "info" : {
    "readOnly" : false,
    "uuid" : UUID("1bc898b2-3b91-45e4-9d8b-0be462d5a157")
    },
    "idIndex" : {
    "v" : 2,
    "key" : {
    "_id" : 1
    },
    "name" : "_id_",
    "ns" : "example.products"
    }
    },
    {
    "name" : "mylogs",
    "type" : "collection",
    "options" : {
    "capped" : true,
    "size" : 256
    },
    "info" : {
    "readOnly" : true,
    "uuid" : UUID("8e62116d-b6a0-490a-808c-258ccb7ea947")
    },
    "idIndex" : {
    "v" : 2,
    "key" : {
    "_id" : 1
    },
    "name" : "_id_",
    "ns" : "example.mylogs"
    }
    }
    ]
    1 liệt kê các bộ sưu tập phi hệ thống cho cơ sở dữ liệu.

  • Đối với người dùng không có quyền truy cập cần thiết,

    [
    {
    "name" : "employees",
    "type" : "collection",
    "options" : {
    "flags" : 1,
    "validator" : {
    "$or" : [
    {
    "phone" : {
    "$exists" : true
    }
    },
    {
    "email" : {
    "$exists" : true
    }
    }
    ]
    }
    },
    "info" : {
    "readOnly" : false,
    "uuid" : UUID("222e18ca-4a10-4a42-a8fe-c39255cc4c55")
    },
    "idIndex" : {
    "v" : 2,
    "key" : {
    "_id" : 1
    },
    "name" : "_id_",
    "ns" : "example.employees"
    }
    },
    {
    "name" : "products",
    "type" : "collection",
    "options" : {
    "flags" : 1
    },
    "info" : {
    "readOnly" : false,
    "uuid" : UUID("1bc898b2-3b91-45e4-9d8b-0be462d5a157")
    },
    "idIndex" : {
    "v" : 2,
    "key" : {
    "_id" : 1
    },
    "name" : "_id_",
    "ns" : "example.products"
    }
    },
    {
    "name" : "mylogs",
    "type" : "collection",
    "options" : {
    "capped" : true,
    "size" : 256
    },
    "info" : {
    "readOnly" : true,
    "uuid" : UUID("8e62116d-b6a0-490a-808c-258ccb7ea947")
    },
    "idIndex" : {
    "v" : 2,
    "key" : {
    "_id" : 1
    },
    "name" : "_id_",
    "ns" : "example.mylogs"
    }
    }
    ]
    1 chỉ liệt kê các bộ sưu tập mà người dùng có đặc quyền.

Khi Shell phiên bản 4.0

use example
db.getCollectionInfos()
9 được kết nối với phiên bản triển khai MongoDB trước đó không hỗ trợ các tùy chọn

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

4 và

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

7,

  • Người dùng phải có quyền truy cập cần thiết để chạy

    { resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

    3

  • Nếu người dùng không có quyền truy cập yêu cầu và chạy

    [
    {
    "name" : "employees",
    "type" : "collection",
    "options" : {
    "flags" : 1,
    "validator" : {
    "$or" : [
    {
    "phone" : {
    "$exists" : true
    }
    },
    {
    "email" : {
    "$exists" : true
    }
    }
    ]
    }
    },
    "info" : {
    "readOnly" : false,
    "uuid" : UUID("222e18ca-4a10-4a42-a8fe-c39255cc4c55")
    },
    "idIndex" : {
    "v" : 2,
    "key" : {
    "_id" : 1
    },
    "name" : "_id_",
    "ns" : "example.employees"
    }
    },
    {
    "name" : "products",
    "type" : "collection",
    "options" : {
    "flags" : 1
    },
    "info" : {
    "readOnly" : false,
    "uuid" : UUID("1bc898b2-3b91-45e4-9d8b-0be462d5a157")
    },
    "idIndex" : {
    "v" : 2,
    "key" : {
    "_id" : 1
    },
    "name" : "_id_",
    "ns" : "example.products"
    }
    },
    {
    "name" : "mylogs",
    "type" : "collection",
    "options" : {
    "capped" : true,
    "size" : 256
    },
    "info" : {
    "readOnly" : true,
    "uuid" : UUID("8e62116d-b6a0-490a-808c-258ccb7ea947")
    },
    "idIndex" : {
    "v" : 2,
    "key" : {
    "_id" : 1
    },
    "name" : "_id_",
    "ns" : "example.mylogs"
    }
    }
    ]
    0, MongoDB sử dụng trường
    [
    {
    "name" : "employees",
    "type" : "collection",
    "options" : {
    "flags" : 1,
    "validator" : {
    "$or" : [
    {
    "phone" : {
    "$exists" : true
    }
    },
    {
    "email" : {
    "$exists" : true
    }
    }
    ]
    }
    },
    "info" : {
    "readOnly" : false,
    "uuid" : UUID("222e18ca-4a10-4a42-a8fe-c39255cc4c55")
    },
    "idIndex" : {
    "v" : 2,
    "key" : {
    "_id" : 1
    },
    "name" : "_id_",
    "ns" : "example.employees"
    }
    },
    {
    "name" : "products",
    "type" : "collection",
    "options" : {
    "flags" : 1
    },
    "info" : {
    "readOnly" : false,
    "uuid" : UUID("1bc898b2-3b91-45e4-9d8b-0be462d5a157")
    },
    "idIndex" : {
    "v" : 2,
    "key" : {
    "_id" : 1
    },
    "name" : "_id_",
    "ns" : "example.products"
    }
    },
    {
    "name" : "mylogs",
    "type" : "collection",
    "options" : {
    "capped" : true,
    "size" : 256
    },
    "info" : {
    "readOnly" : true,
    "uuid" : UUID("8e62116d-b6a0-490a-808c-258ccb7ea947")
    },
    "idIndex" : {
    "v" : 2,
    "key" : {
    "_id" : 1
    },
    "name" : "_id_",
    "ns" : "example.mylogs"
    }
    }
    ]
    8 được trả về bởi
    [
    {
    "name" : "employees",
    "type" : "collection",
    "options" : {
    "flags" : 1,
    "validator" : {
    "$or" : [
    {
    "phone" : {
    "$exists" : true
    }
    },
    {
    "email" : {
    "$exists" : true
    }
    }
    ]
    }
    },
    "info" : {
    "readOnly" : false,
    "uuid" : UUID("222e18ca-4a10-4a42-a8fe-c39255cc4c55")
    },
    "idIndex" : {
    "v" : 2,
    "key" : {
    "_id" : 1
    },
    "name" : "_id_",
    "ns" : "example.employees"
    }
    },
    {
    "name" : "products",
    "type" : "collection",
    "options" : {
    "flags" : 1
    },
    "info" : {
    "readOnly" : false,
    "uuid" : UUID("1bc898b2-3b91-45e4-9d8b-0be462d5a157")
    },
    "idIndex" : {
    "v" : 2,
    "key" : {
    "_id" : 1
    },
    "name" : "_id_",
    "ns" : "example.products"
    }
    },
    {
    "name" : "mylogs",
    "type" : "collection",
    "options" : {
    "capped" : true,
    "size" : 256
    },
    "info" : {
    "readOnly" : true,
    "uuid" : UUID("8e62116d-b6a0-490a-808c-258ccb7ea947")
    },
    "idIndex" : {
    "v" : 2,
    "key" : {
    "_id" : 1
    },
    "name" : "_id_",
    "ns" : "example.mylogs"
    }
    }
    ]
    9 để trả về danh sách các bộ sưu tập gần đúng cho người dùng.

Bắt đầu từ MongoDB 4.2, nếu khách hàng phát hành

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

2 ngắt kết nối trước khi hoạt động hoàn thành, MongoDB đánh dấu

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

2 để chấm dứt bằng cách sử dụng
use example
db.getCollectionInfos( { name: "employees" } )
2

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

2
disconnects before the operation completes, MongoDB marks

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

2
for termination using
use example
db.getCollectionInfos( { name: "employees" } )
2

Bắt đầu từ MongoDB 4.4, để chạy trên một thành viên tập hợp, các hoạt động

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

3 yêu cầu thành viên phải ở trạng thái
use example
db.getCollectionInfos( { name: "employees" } )
4 hoặc
use example
db.getCollectionInfos( { name: "employees" } )
5. Nếu thành viên ở một trạng thái khác, chẳng hạn như
use example
db.getCollectionInfos( { name: "employees" } )
6, các lỗi hoạt động.

Trong các phiên bản trước, các hoạt động cũng chạy khi thành viên ở

use example
db.getCollectionInfos( { name: "employees" } )
6. Các hoạt động đợi cho đến khi thành viên chuyển sang
use example
db.getCollectionInfos( { name: "employees" } )
8

Thông tin trả về sau đây cho tất cả các bộ sưu tập trong cơ sở dữ liệu

use example
db.getCollectionInfos( { name: "employees" } )
9:

use example
db.getCollectionInfos()

Phương thức trả về một mảng các tài liệu có chứa thông tin thu thập:

[
{
"name" : "employees",
"type" : "collection",
"options" : {
"flags" : 1,
"validator" : {
"$or" : [
{
"phone" : {
"$exists" : true
}
},
{
"email" : {
"$exists" : true
}
}
]
}
},
"info" : {
"readOnly" : false,
"uuid" : UUID("222e18ca-4a10-4a42-a8fe-c39255cc4c55")
},
"idIndex" : {
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "example.employees"
}
},
{
"name" : "products",
"type" : "collection",
"options" : {
"flags" : 1
},
"info" : {
"readOnly" : false,
"uuid" : UUID("1bc898b2-3b91-45e4-9d8b-0be462d5a157")
},
"idIndex" : {
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "example.products"
}
},
{
"name" : "mylogs",
"type" : "collection",
"options" : {
"capped" : true,
"size" : 256
},
"info" : {
"readOnly" : true,
"uuid" : UUID("8e62116d-b6a0-490a-808c-258ccb7ea947")
},
"idIndex" : {
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "example.mylogs"
}
}
]

Để yêu cầu thông tin thu thập cho một bộ sưu tập cụ thể, chỉ định tên thu thập khi gọi phương thức, như sau:

use example
db.getCollectionInfos( { name: "employees" } )

Phương thức trả về một mảng với một tài liệu duy nhất chi tiết thông tin thu thập cho bộ sưu tập

[
{
"name" : "employees",
"type" : "collection",
"options" : {
"flags" : 1,
"validator" : {
"$or" : [
{
"phone" : {
"$exists" : true
}
},
{
"email" : {
"$exists" : true
}
}
]
}
},
"info" : {
"readOnly" : false,
"uuid" : UUID("222e18ca-4a10-4a42-a8fe-c39255cc4c55")
},
"idIndex" : {
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "example.employees"
}
}
]
0 trong cơ sở dữ liệu
use example
db.getCollectionInfos( { name: "employees" } )
9.

[
{
"name" : "employees",
"type" : "collection",
"options" : {
"flags" : 1,
"validator" : {
"$or" : [
{
"phone" : {
"$exists" : true
}
},
{
"email" : {
"$exists" : true
}
}
]
}
},
"info" : {
"readOnly" : false,
"uuid" : UUID("222e18ca-4a10-4a42-a8fe-c39255cc4c55")
},
"idIndex" : {
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "example.employees"
}
}
]

Bạn có thể chỉ định bộ lọc trên bất kỳ trường nào được trả về bởi

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

2

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

2

Ví dụ: lệnh sau trả về thông tin cho tất cả các bộ sưu tập trong cơ sở dữ liệu

use example
db.getCollectionInfos( { name: "employees" } )
9 trong đó
[
{
"name" : "employees",
"type" : "collection",
"options" : {
"flags" : 1,
"validator" : {
"$or" : [
{
"phone" : {
"$exists" : true
}
},
{
"email" : {
"$exists" : true
}
}
]
}
},
"info" : {
"readOnly" : false,
"uuid" : UUID("222e18ca-4a10-4a42-a8fe-c39255cc4c55")
},
"idIndex" : {
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "example.employees"
}
}
]
4 là

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )

2:

use example
db.getCollectionInfos( { "info.readOnly" : true } )

Lệnh trả về như sau:

{ resource: { db: "test", collection: "foo" }, actions: [ "find" ] }

0