2013-06-06 30 views
1

我使用的是Mongo PHP擴展,我想在php中加入2個集合。我搜索了四周,但人們通常會說「你可以使用map-reduce」,但我不能在php中這樣做。如何在Php程序語言中使用Mongodb加入2個集合?

我的數據是這樣的:

users 
{ 
    "_id": "4ca30369fd0e910ecc000006", 
    "login": "user11", 
    "pass": "example_pass", 
    "date": "2010-09-29" 
}, 
{ 
    "_id": "4ca30373fd0e910ecc000007", 
    "login": "user22", 
    "pass": "example_pass", 
    "date": "2010-09-29" 
} 

news 
{ 
    "_id": "4ca305c2fd0e910ecc000003", 
    "name": "news 333", 
    "content": "news content 3333", 
    "user_id": "4ca30373fd0e910ecc000007", 
    "date": "2010-09-29" 
}, 
{ 
    "_id": "4ca305c2fd0e910ecc00000b", 
    "name": "news 222", 
    "content": "news content 2222", 
    "user_id": "4ca30373fd0e910ecc000007", 
    "date": "2010-09-29" 
}, 
{ 
    "_id": "4ca305b5fd0e910ecc00000a", 
    "name": "news 111", 
    "content": "news content", 
    "user_id": "4ca30369fd0e910ecc000006", 
    "date": "2010-09-29" 
} 

我如何用PHP編寫此SQL與MongoDB的?

SELECT n.*, u.* 
FROM news AS n 
INNER JOIN users AS u ON n.user_id = u.id 
+0

「我搜索。人們通常說」你可以使用map-reduce「。但我不能在PHP中」該聲明是不正確的, PHP驅動程序已完全支持地圖縮小,無論哪種方式,我不會使用地圖縮減爲此 – Sammaye

回答