Con trỏ có thể điều chỉnh chỉ được sử dụng với các bộ sưu tập được giới hạn. Chúng không được đóng lại khi dữ liệu cuối cùng được truy xuất mà được giữ mở và vị trí con trỏ đánh dấu vị trí tài liệu cuối cùng. Nếu nhận được nhiều dữ liệu hơn, việc lặp lại con trỏ sẽ tiếp tục từ tài liệu cuối cùng nhận được
TAILABLE_AWAITMột con trỏ có thể theo đuôi với bộ tùy chọn đang chờ
Tạo một con trỏ có thể theo đuôi sẽ chờ vài giây sau khi trả về tập hợp kết quả đầy đủ để nó có thể thu thập và trả về dữ liệu bổ sung được thêm vào trong quá trình truy vấn
KHÍ THẢIMột con trỏ xả
MongoDB sẽ truyền kết quả theo lô đến máy khách mà không cần đợi máy khách yêu cầu từng đợt, giúp giảm độ trễ
lớp pymongo. con trỏ. Con trỏ[bộ sưu tập , bộ lọc=Không có , hình chiếu=Không , bỏ qua=0 , giới hạn=0 , no_cursor_timeout=Sai , cursor_type=Kiểu con trỏ. NON_TAILABLE , sắp xếp=Không có , allow_partial_results=Sai , oplog_replay=Sai , batch_size=0 , đối chiếu=Không , gợi ý=Không có , max_scan=Không , max_time_ms=Không , tối đa=Không , phút=Không , return_key=Sai , show_record_id=Sai , ảnh chụp nhanh=Sai , nhận xét=None , phiên=Không có , allow_disk_use=Không có]Tạo một con trỏ mới
Các nhà phát triển ứng dụng không nên gọi trực tiếp - thay vào đó hãy xem
Xem thêm
Tài liệu MongoDB về con trỏ
c[index]See and read the warning
__getitem__[chỉ mục. ] → pymongo. đánh máy. _DocumentType__getitem__[chỉ mục. ] → [_Loại tài liệu]Get a single document or a slice of documents from this cursor
Warning
A is not a Python . Each index access or slice requires that a new query be run using skip and limit. Do not iterate the cursor using index accesses. The following example is extremely inefficient and may return surprising results
cursor = db.collection.find[] # Warning: This runs a new query for each document. # Don't do this! for idx in range[10]: print[cursor[idx]]
Raises if this cursor has already been used
To get a single document use an integral index, e. g
>>> db.test.find[][50]
An will be raised if the index is negative or greater than the amount of documents in this cursor. Any limit previously applied to this cursor will be ignored
To get a slice of documents use a slice index, e. g
>>> db.test.find[][20:25]
This will return this cursor with a limit of
>>> db.test.find[][50]5 and skip of
>>> db.test.find[][50]6 applied. Using a slice index will override any prior limits or skips applied to this cursor [including those applied through previous calls to this method]. Raises when the slice has a step, a negative start value, or a stop value less than or equal to the start valueParameters
index. An integer or slice index to be applied to this cursor
Set arbitrary query flags using a bitmask
To set the tailable flag. cursor. add_option[2]
property địa chỉ. Tùy chọn[Tuple[, Bất kỳ]]The [host, port] of the server used, or None
Changed in version 3. 0. Renamed from “conn_id”.
property còn sống.Does this cursor have the potential to return more data?
This is mostly useful with tailable cursors since they will stop iterating even though they may return more results in the future
With regular cursors, simply use a for loop instead of
for doc in collection.find[]: print[doc]
Note
Even if is True, can raise . can also be True while iterating a cursor from a failed server. In this case will return False after fails to retrieve the next batch of results from the server
allow_disk_use[allow_disk_use. ] → [pymongo. đánh máy. _Loại tài liệu]Specifies whether MongoDB can use temporary disk files while processing a blocking sort operation
Raises if allow_disk_use is not a boolean
Note
allow_disk_use requires server version >= 4. 4
Parametersallow_disk_use. if True, MongoDB may use temporary disk files to store data exceeding the system memory limit while processing a blocking sort operation
New in version 3. 11
batch_size[batch_size. ] → [pymongo. đánh máy. _Loại tài liệu]Limits the number of documents returned in one batch. Each batch requires a round trip to the server. It can be adjusted to optimize performance and limit data transfer
Note
batch_size can not override MongoDB’s internal limits on the amount of data it will return to the client in a single batch [i. e if you set batch size to 1,000,000,000, MongoDB will currently only return 4-16MB of results per batch]
Raises if batch_size is not an integer. Raises if batch_size is less than
>>> db.test.find[][20:25]8. Raises if this has already been used. The last batch_size applied to this cursor takes precedenceParameters
batch_size. The size of each batch of results requested
Get a clone of this cursor
Returns a new Cursor instance with options matching those that have been set on the current instance. The clone will be completely unevaluated, even if the current instance has been partially or completely evaluated
close[] →Explicitly close / kill this cursor
collation[đối chiếu. [[[, ], ]]] → [_Loại tài liệu]Adds a to this query
Raises if collation is not an instance of or a
for doc in collection.find[]: print[doc]4. Raises if this has already been used. Only the last collation applied to this cursor has any effectParameters
collation. An instance of
The that this is iterating
bình luận[bình luận. ] → [pymongo. đánh máy. _Loại tài liệu]Thêm một 'bình luận' vào con trỏ
http. //mongodb. com/docs/manual/reference/operator/comment/
Parametersnhận xét. Một chuỗi để đính kèm vào truy vấn nhằm giúp diễn giải và theo dõi hoạt động trong nhật ký máy chủ và trong dữ liệu hồ sơ
Mới trong phiên bản 2. 7
thuộc tính cursor_id. Tùy chọn[]Trả về id của con trỏ
Mới trong phiên bản 2. 2
khác biệt[khóa. ] →Nhận danh sách các giá trị riêng biệt cho khóa trong số tất cả các tài liệu trong tập hợp kết quả của truy vấn này
Tăng nếu khóa không phải là phiên bản của
for doc in collection.find[].sort['field', pymongo.ASCENDING]: print[doc]1 [ trong python 3]
Phương thức tuân theo thể hiện được gọi
ParametersChìa khóa. tên của khóa mà chúng tôi muốn nhận các giá trị riêng biệt
Xem thêm
Returns an explain plan record for this cursor
Note
This method uses the default verbosity mode of the explain command,
for doc in collection.find[].sort['field', pymongo.ASCENDING]: print[doc]8. To use a different verbosity use to run the explain command directly
Xem thêm
The MongoDB documentation on explain
hint[chỉ mục. [[, [[, [, , [, ]]]]]]] → [pymongo. đánh máy. _Loại tài liệu]Adds a ‘hint’, telling Mongo the proper index to use for the query
Judicious use of hints can greatly improve query performance. When doing a query on multiple fields [at least one of which is indexed] pass the indexed field as a hint to the query. Raises if the provided hint requires an index that does not exist on this collection, and raises if this cursor has already been used
index should be an index as passed to [e. g.
for doc in collection.find[].sort[[ ['field1', pymongo.ASCENDING], ['field2', pymongo.DESCENDING]]]: print[doc]3] or the name of the index. If index is
for doc in collection.find[].sort[[ ['field1', pymongo.ASCENDING], ['field2', pymongo.DESCENDING]]]: print[doc]4 any existing hint for this query is cleared. The last hint applied to this cursor takes precedence over all othersParameters
index. index to hint on [as an index specifier]
Limits the number of results to be returned by this cursor
Raises if limit is not an integer. Raises if this has already been used. The last limit applied to this cursor takes precedence. A limit of
>>> db.test.find[][20:25]8 is equivalent to no limitParameters
limit. the number of results to return
Xem thêm
The MongoDB documentation on limit
max[thông số kỹ thuật. [[, [, , [, ]]]]] → [pymongo. đánh máy. _Loại tài liệu]Adds
for doc in collection.find[].sort[[ ['field1', pymongo.ASCENDING], ['field2', pymongo.DESCENDING]]]: print[doc]9 operator that specifies upper bound for specific index
When using
for doc in collection.find[].sort[[ ['field1', pymongo.ASCENDING], ['field2', pymongo.DESCENDING]]]: print[doc]9, should also be configured to ensure the query uses the expected index and starting in MongoDB 4. 2 will be requiredParameters
spec. a list of field, limit pairs specifying the exclusive upper bound for all keys of a specific index in order
Changed in version 3. 8. Các con trỏ không dùng nữa sử dụng
for doc in collection.find[].sort[[ ['field1', pymongo.ASCENDING], ['field2', pymongo.DESCENDING]]]: print[doc]9 mà không có.
Mới trong phiên bản 2. 7
max_await_time_ms[max_await_time_ms. []] → [pymongo. đánh máy. _Loại tài liệu]Chỉ định giới hạn thời gian cho thao tác getMore trên con trỏ. Đối với tất cả các loại con trỏ khác, max_await_time_ms bị bỏ qua
Tăng nếu max_await_time_ms không phải là số nguyên hoặc
for doc in collection.find[].sort[[ ['field1', pymongo.ASCENDING], ['field2', pymongo.DESCENDING]]]: print[doc]4. Tăng nếu điều này đã được sử dụng
Note
max_await_time_ms yêu cầu phiên bản máy chủ >= 3. 2
Parametersmax_await_time_ms. giới hạn thời gian sau đó hoạt động bị hủy bỏ
Mới trong phiên bản 3. 2
max_scan[max_scan. []] → [pymongo. đánh máy. _Loại tài liệu]KHÔNG DÙNG - Giới hạn số lượng tài liệu cần quét khi thực hiện truy vấn
Tăng nếu con trỏ này đã được sử dụng. Chỉ cái cuối cùng được áp dụng cho con trỏ này mới có tác dụng
Parametersmax_scan. số lượng tài liệu tối đa để quét
Đã thay đổi trong phiên bản 3. 7. Không dùng nữa. Hỗ trợ cho tùy chọn này không được dùng nữa trong MongoDB 4. 0. Thay vào đó, hãy sử dụng để giới hạn thời gian thực hiện phía máy chủ.
max_time_ms[max_time_ms. []] → [pymongo. đánh máy. _Loại tài liệu]Chỉ định giới hạn thời gian cho thao tác truy vấn. Nếu quá thời gian quy định, hoạt động sẽ bị hủy bỏ và được nâng lên. Nếu max_time_ms là
for doc in collection.find[].sort[[ ['field1', pymongo.ASCENDING], ['field2', pymongo.DESCENDING]]]: print[doc]4 thì không có giới hạn nào được áp dụng
Tăng nếu max_time_ms không phải là số nguyên hoặc
for doc in collection.find[].sort[[ ['field1', pymongo.ASCENDING], ['field2', pymongo.DESCENDING]]]: print[doc]4. Tăng nếu điều này đã được sử dụngParameters
max_time_ms. giới hạn thời gian sau đó hoạt động bị hủy bỏ
Thêm toán tử cursor
0 chỉ định giới hạn dưới cho chỉ mục cụ thể
Khi sử dụng cursor
0, cũng nên được định cấu hình để đảm bảo truy vấn sử dụng chỉ mục dự kiến và bắt đầu trong MongoDB 4. 2 sẽ được yêu cầu
thông số kỹ thuật. một danh sách các cặp trường, giới hạn chỉ định giới hạn dưới bao gồm cho tất cả các khóa của một chỉ mục cụ thể theo thứ tự
Đã thay đổi trong phiên bản 3. 8. Các con trỏ không dùng nữa sử dụng cursor
0 mà không có.
Mới trong phiên bản 2. 7
tiếp theo[] → pymongo. đánh máy. _Loại tài liệuTiến con trỏ
remove_option[khẩu trang. ] → [pymongo. đánh máy. _Loại tài liệu]Bỏ đặt cờ truy vấn tùy ý bằng bitmask
Để bỏ đặt cờ tailable. con trỏ. remove_option[2]
thuộc tính đã truy xuất.Số lượng tài liệu được truy xuất cho đến nay
tua lại[] → [pymongo. đánh máy. _Loại tài liệu]Tua lại con trỏ này về trạng thái chưa được đánh giá
Đặt lại con trỏ này nếu nó đã được đánh giá một phần hoặc toàn bộ. Mọi tùy chọn có trên con trỏ sẽ vẫn có hiệu lực. Việc lặp lại trong tương lai được thực hiện trên con trỏ này sẽ khiến các truy vấn mới được gửi đến máy chủ, ngay cả khi dữ liệu kết quả đã được con trỏ này truy xuất
thuộc tính phiên. Tùy chọn[]Của con trỏ hoặc Không có
Mới trong phiên bản 3. 6
bỏ qua[bỏ qua. ] → [pymongo. đánh máy. _Loại tài liệu]Bỏ qua kết quả bỏ qua đầu tiên của con trỏ này
Tăng nếu bỏ qua không phải là một số nguyên. Tăng nếu bỏ qua ít hơn
>>> db.test.find[][20:25]8. Tăng nếu điều này đã được sử dụng. Lần bỏ qua cuối cùng được áp dụng cho con trỏ này sẽ được ưu tiênParameters
nhảy. số lượng kết quả để bỏ qua
Sắp xếp kết quả của con trỏ này
Truyền tên trường và hướng, hoặc
________số 8_______
Để sắp xếp theo nhiều trường, hãy chuyển danh sách các cặp [khóa, hướng]
for doc in collection.find[].sort[[ ['field1', pymongo.ASCENDING], ['field2', pymongo.DESCENDING]]]: print[doc]
Kết quả tìm kiếm văn bản có thể được sắp xếp theo mức độ liên quan
cursor = db.test.find[ {'$text': {'$search': 'some words'}}, {'score': {'$meta': 'textScore'}}] # Sort by 'score' field. cursor.sort[[['score', {'$meta': 'textScore'}]]] for doc in cursor: print[doc]
Để biết thêm chức năng tìm kiếm văn bản nâng cao, hãy xem MongoDB's Atlas Search
Tăng nếu con trỏ này đã được sử dụng. Chỉ cái cuối cùng được áp dụng cho con trỏ này mới có tác dụng
Parameterskey_or_list. một khóa duy nhất hoặc một danh sách các cặp [khóa, hướng] chỉ định các khóa để sắp xếp
hướng [tùy chọn]. only used if key_or_list is a single key, if not given is assumed
Thêm mệnh đề $where vào truy vấn này
Đối số mã phải là phiên bản của
for doc in collection.find[].sort['field', pymongo.ASCENDING]: print[doc]1 [ trong python 3] hoặc chứa biểu thức JavaScript. Biểu thức này sẽ được đánh giá cho từng tài liệu được quét. Chỉ những tài liệu mà biểu thức đánh giá là true mới được trả về dưới dạng kết quả. Từ khóa this đề cập đến đối tượng hiện đang được quét. Ví dụ
# Find all documents where field "a" is less than "b" plus "c". for doc in db.test.find[].where['this.a < [this.b + this.c]']: print[doc]
Tăng nếu mã không phải là phiên bản của
for doc in collection.find[].sort['field', pymongo.ASCENDING]: print[doc]1 [ trong python 3]. Tăng nếu điều này đã được sử dụng. Chỉ lệnh gọi cuối cùng áp dụng cho a mới có hiệu lực