{
"_id": ObjectId("5271ab5133f6792263dd8e8e"),
"address": "131031000947",
"description": "bind",
"group_id": ObjectId("505efb8a3b62c5d7bc8c624f"),
"last_active_time": 1386768863, // epoch 秒數
"location": "test",
"status": "offline",
"user_id": ObjectId("4ee175ff82bc6273d0d4672f"),
"validate_code": "123456"
}
找出 當前時間 (epoch) - last_active_time > 300 秒 且 status = "online" 的文件。
300)'},
{status: "online"}
]
}).count()
$where 允許執行 JavaScript 運算式,this 指向當前文件。idle_seconds),配合一般索引查詢;或使用 Aggregation Pipeline $subtract 配合 $match (MongoDB 3.6+ 支援索引)。