EnterpriseDB / mongo_fdw

PostgreSQL foreign data wrapper for MongoDB
GNU Lesser General Public License v3.0
330 stars 70 forks source link

Implement BsonIterSubObject for the meta driver. Fixes #34 and #38. #40

Closed bremac closed 8 years ago

bremac commented 8 years ago

The previous implementation of BsonIterSubObject was leaving BSON objects uninitialized, which caused crashes (#34) and missing nested fields (#38) with the mongo meta driver. This implementation fixes both issues for me.

bremac commented 8 years ago

Using the following test case from expected/mongo_fdw.out demonstrates the fix:

CREATE FOREIGN TABLE country_elections (
_id NAME,
"lastElections.type" VARCHAR,
"lastElections.date" TIMESTAMP
) SERVER mongo_server OPTIONS (database 'mongo_fdw_regress', collection 'countries');
SELECT * FROM country_elections;

Output before (well, output when it didn't crash postgres):

           _id            | lastElections.type | lastElections.date 
--------------------------+--------------------+--------------------
 5381ccf9d6d81c8e8bf0434f |                    | 
 5381ccf9d6d81c8e8bf04350 |                    | 
 5381ccf9d6d81c8e8bf04351 |                    | 

Output after:

           _id            | lastElections.type | lastElections.date  
--------------------------+--------------------+---------------------
 5381ccf9d6d81c8e8bf0434f | presedential       | 2014-05-25 00:00:00
 5381ccf9d6d81c8e8bf04350 | parliamentary      | 2011-10-09 00:00:00
 5381ccf9d6d81c8e8bf04351 | parliamentary      | 2010-11-28 00:00:00