1
我有一個集合的「細節」。MongoDB查詢同一個表作爲別名
{
"_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;
你有什麼試過?從[SQL比較](http://docs.mongodb.org/manual/reference/sql-comparison/)和[SQL to Aggregation Framework]開始(http://docs.mongodb.org/manual/reference/sql -aggregation-comparison /) – WiredPrairie
爲什麼你不能首先查詢「parent」,然後用它來查詢其他的東西? –
嘗試查找和聚合...沒有工作......我也需要這個從PHP-lithium框架運行! –