Làm cách nào để đếm tài liệu trong tập bản đồ mongodb?
Ngày đăng:24/01/2023
Trả lời:0
Lượt xem:66
Mỗi tài liệu được trả về bởi truy vấn Tìm kiếm Atlas được chỉ định một số điểm dựa trên mức độ liên quan và các tài liệu có trong tập kết quả được trả về theo thứ tự từ điểm cao nhất đến thấp nhất
Nhiều yếu tố có thể ảnh hưởng đến điểm số của tài liệu, bao gồm
Vị trí của thuật ngữ tìm kiếm trong tài liệu,
Tần suất xuất hiện của cụm từ tìm kiếm trong tài liệu,
Loại truy vấn sử dụng,
Loại truy vấn sử dụng
Điểm được gán cho tài liệu được trả về là một phần của siêu dữ liệu của tài liệu. Bạn có thể bao gồm điểm số của từng tài liệu được trả về cùng với kết quả đã đặt bằng cách sử dụng
trong đường ống tổng hợp của bạn. Sau một giai đoạn, bạn không cần bao gồm giảm dần vì Tìm kiếm Atlas trả về các tài liệu từ điểm cao nhất đến thấp nhất theo mặc định
Truy vấn ví dụ sau sử dụng một giai đoạn để thêm trường có tên
Bạn có thể tìm thêm thông tin về thuật toán tính điểm Lucene trong Tài liệu về Lucene.
Các tùy chọn sửa đổi điểm sau đây có sẵn cho tất cả các nhà khai thác. Để biết chi tiết và ví dụ, hãy nhấp vào bất kỳ tùy chọn nào sau đây
boost
Tùy chọn boost nhân điểm cơ sở của kết quả với một số đã cho hoặc giá trị của trường số trong tài liệu. Ví dụ: bạn có thể sử dụng boost để tăng tầm quan trọng của một số tài liệu phù hợp trong kết quả
Ghi chú
Không thể sử dụng các tùy chọn boost và constant cùng nhau
Tùy chọn ________ 83 _______ với
1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score:8.154602050781256 },7 {8 plot:"When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score:511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score:516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score:521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score:526 }27]
7 cũng giống như phép nhân bằng cách sử dụng tùy chọn với một
1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score:8.154602050781256 },7 {8 plot:"When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score:511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score:516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score:521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score:526 }27]
7, nhưng bạn không thể chỉ định cả hai
1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score:8.154602050781256 },7 {8 plot:"When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score:511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score:516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score:521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score:526 }27]
7
chuỗi
có điều kiện
Tên của trường số có giá trị để nhân điểm cơ sở mặc định với. Phải có
1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score:8.154602050781256 },7 {8 plot:"When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score:511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score:516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score:521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score:526 }27]
1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score:8.154602050781256 },7 {8 plot:"When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score:511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score:516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score:521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score:526 }27]
7 nếu trường số được chỉ định thông qua
1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score:8.154602050781256 },7 {8 plot:"When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score:511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score:516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score:521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score:526 }27]
7 không được tìm thấy trong tài liệu. Nếu bỏ qua, mặc định là
9. Bạn chỉ có thể chỉ định điều này nếu bạn chỉ định
1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score:8.154602050781256 },7 {8 plot:"When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score:511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score:516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score:521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score:526 }27]
5 được thay thế bằng giá trị constant được chỉ định
1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score:8.154602050781256 },7 {8 plot:"When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score:511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score:516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score:521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score:526 }27]
Sửa đổi điểm của một toán tử sau khi tổng hợp điểm từ các tài liệu được nhúng phù hợp
Ghi chú
Tùy chọn chỉ mục, toán tử và tùy chọn tính điểm của Tìm kiếm bản đồ đang ở chế độ xem trước. Khi một chỉ mục Tìm kiếm Atlas trên một bộ bản sao hoặc một phân đoạn MongoDB đạt đến giới hạn hai tỷ tài liệu của Lucene, Tìm kiếm Atlas sẽ không lập chỉ mục các tài liệu mới hoặc áp dụng các bản cập nhật cho các tài liệu hiện có cho chỉ mục đó. Một giải pháp để khắc phục hạn chế này sẽ được áp dụng khi chúng tôi cung cấp tính năng này rộng rãi. Trong khi đó, nhóm Hỗ trợ đám mây MongoDB sẽ giúp khắc phục mọi sự cố liên quan đến việc sử dụng tính năng này như một phần trong hợp đồng của bạn
8 - Chọn điểm trung bình (trung bình cộng) của tất cả các tài liệu được nhúng phù hợp. Tìm kiếm Atlas chỉ bao gồm điểm số của các tài liệu được nhúng phù hợp khi tính toán mức trung bình. Tìm kiếm Atlas không tính các tài liệu được nhúng không đáp ứng các vị từ truy vấn là tài liệu có điểm số bằng 0
6 của nhà điều hành boost9. Tuy nhiên, đối với điểm số của hàm yêu cầu tùy chọn
1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score:8.154602050781256 },7 {8 plot:"When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score:511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score:516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score:521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score:526 }27]
7, trường số mà bạn chỉ định là
1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score:8.154602050781256 },7 {8 plot:"When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score:511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score:516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score:521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score:526 }27]
7 cho biểu thức phải nằm trong toán tử
1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score:8.154602050781256 },7 {8 plot:"When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score:511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score:516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score:521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score:526 }27]
7. Ví dụ: trong truy vấn mẫu bên dưới, trường constant3 được chỉ định bên trong tùy chọn
1 cho phép bạn thay đổi điểm số cuối cùng của tài liệu bằng trường số. Bạn có thể chỉ định trường số để tính điểm cuối cùng thông qua một. Nếu kết quả cuối cùng của điểm chức năng nhỏ hơn
6 của nhà điều hành boost9. Tuy nhiên, đối với các biểu thức điểm số của hàm yêu cầu tùy chọn
1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score:8.154602050781256 },7 {8 plot:"When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score:511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score:516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score:521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score:526 }27]
7, trường số mà bạn chỉ định là
1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score:8.154602050781256 },7 {8 plot:"When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score:511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score:516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score:521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score:526 }27]
7 cho biểu thức phải nằm trong toán tử
1[2 {3 plot: 'Several months after witnessing a murder, residents of Tower Block 31 find themselves being picked off by a sniper, pitting those lucky enough to be alive into a battle for survival.',4 title: 'Tower Block',5 score:8.154602050781256 },7 {8 plot:"When a group of hard-working guys find out they've fallen victim to their wealthy employer's Ponzi scheme, they conspire to rob his high-rise residence.",9 title: 'Tower Heist',10 score:511 },12 {13 plot: 'Toru Kojima and his friend Koji are young student boys with one thing in common - they both love to date older women. Koji is a playboy with several women, young and older, whereas Toru is a romantic with his heart set on on certain lady.',14 title: 'Tokyo Tower',15 score:516 },17 {18 plot: 'A middle-aged mental patient suffering from a split personality travels to Italy where his two personalities set off all kinds of confusing developments.',19 title: 'The Leaning Tower',20 score:521 },22 {23 plot: 'A documentary that questions the cost -- and value -- of higher education in the United States.',24 title: 'Ivory Tower',25 score:526 }27]
23 trong các giai đoạn tiếp theo của quy trình tổng hợp của bạn. Bạn có thể sử dụng các giai đoạn sau sau giai đoạn của mình theo thứ tự sau để bình thường hóa điểm số
Các ví dụ sau minh họa cách chuẩn hóa điểm số cho một số truy vấn đối với bộ sưu tập
{"$addFields":{"score":{"$meta":"searchScore"}}}
1 ở phần trước bằng cách sử dụng các giai đoạn và sau giai đoạn
Làm cách nào để có được tổng số trong MongoDB?
Trả về số lượng tài liệu khớp với truy vấn find() cho bộ sưu tập hoặc chế độ xem. db.bộ sưu tập.phương thức đếm() không thực hiện thao tác find() mà thay vào đó đếm và trả về số lượng kết quả khớp với một truy vấn.
Có bao nhiêu tài liệu trong MongoDB?
Nếu bạn chỉ định số lượng tài liệu tối đa cho một bộ sưu tập giới hạn bằng cách sử dụng tham số max để tạo, giới hạn phải là ít hơn 2^32 tài liệu. If you do not specify a maximum number of documents when creating a capped collection, there is no limit on the number of documents.
Làm cách nào để lấy số lượng tài liệu trong tập hợp MongoDB?
The giai đoạn $count trả về số lượng tài liệu còn lại trong quy trình tổng hợp và gán giá trị cho trường có tên là pass_scores.
Phương thức nào trả về số lượng tài liệu cho một truy vấn nhất định?
count() cho phép bạn xác định số lượng tài liệu trong một bộ sưu tập hoặc truy vấn.