我有一個包含state列舉欄位型別并且只接受三個值的模型
active
disabled
deleted
目前正在過濾以獲取所有活動的
const query = {state : "active" ... other filters here}
const posts = await post.find(query)
但是我有一個案例,我需要獲取兩者都說明的帖子,active并且disabled我在貓鼬檔案中搜索了我可以使用的東西,但目前我什么也沒找到,我想要一些干凈的東西來實作這個代碼
const query1 = {state : "active" ... other filters here}
const posts1 = await post.find(query1)
const query2 = {state : "disabled" ... other filters here}
const posts2 = await post.find(query2)
const posts = {...posts1, ...posts2}
uj5u.com熱心網友回復:
const query = { state: { $in: [ "active", "disabled"] } }
const posts = await post.find(query)
這將生成狀態為active或的帖子串列disabled。
$in 運算子選擇欄位值等于指定陣列中的任何值的檔案。要指定 $in 運算式,請使用以下原型:
來自MongoDB 檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/453930.html
標籤:javascript 节点.js mongodb 猫鼬
