![](/img/trans.png)
[英]How to find document and single subdocument matching given criterias in MongoDB collection
[英]How can we find random document matching given query and update it atomically in mongoDB?
FindOneAndUpdate 按順序選擇文檔。 有沒有辦法選擇與我們的查詢匹配的隨機文檔並自動更新它?
要獲取隨機文檔,請使用$sample 。
要更新它,請使用 FindOneAndUpdate 中的聚合管道。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.