我有一个集合“详细信息”。
{
"_id": ObjectId("50e876e49d5d0cbc08000001"),
"user_id": "50e876e49d5d0cbc08000000",
"left": NumberInt(1),
"right": NumberInt(2)
}
{
"_id": ObjectId("50e876b79d5d0c040a000001"),
"user_id": "50e876b79d5d0c040a000000",
"left": NumberInt(3),
"right": NumberInt(4)
}
我想在 MongoDB 中编写一个类似于 SQL 的查询,如下所示:
SELECT node.user_id
FROM details AS node,
details AS parent
WHERE node.left BETWEEN parent.left AND parent.right
AND parent.user_id = "50e876e49d5d0cbc08000000"
ORDER BY node.left;