CREATE EXTENSION mongo_fdw;
CREATE SERVER mongo_server
FOREIGN DATA WRAPPER mongo_fdw
OPTIONS ( address '127.0.0.1' , port '27017' ) ;
CREATE USER MAPPING FOR enterprisedb
SERVER mongo_server
OPTIONS ( username 'mongo_user' , password 'mongo_pass' ) ;
CREATE FOREIGN TABLE warehouse
(
_id name,
warehouse_id int ,
warehouse_name text ,
warehouse_created timestamptz
)
SERVER mongo_server
OPTIONS ( database 'db' , collection 'warehouse' ) ;
SELECT * FROM warehouse WHERE warehouse_id = 1 ;
_id | warehouse_id | warehouse_name | warehouse_created
53720 b1904864dc1f5a571a0 | 1 | UPS | 2014 - 12 - 12 12 :42 :10 + 05 :30
( 1 row )
db. warehouse. find
(
{
"warehouse_id" : 1
}
) . pretty( )
{
"_id" : ObjectId( "53720b1904864dc1f5a571a0" ) ,
"warehouse_id" : 1 ,
"warehouse_name" : "UPS" ,
"warehouse_created" : ISODate( "2014-12-12T07:12:10Z" )
}
INSERT INTO warehouse VALUES ( 0 , 2 , 'Laptop' , '2015-11-11T08:13:10Z' ) ;
db. warehouse. insert
(
{
"warehouse_id" : NumberInt( 2 ) ,
"warehouse_name" : "Laptop" ,
"warehouse_created" : ISODate( "2015-11-11T08:13:10Z" )
}
)
DELETE FROM warehouse WHERE warehouse_id = 2 ;
db. warehouse. remove
(
{
"warehouse_id" : 2
}
)
UPDATE warehouse SET warehouse_name = 'UPS_NEW' WHERE warehouse_id = 1 ;
db. warehouse. update
(
{
"warehouse_id" : 1
},
{
"warehouse_id" : 1 ,
"warehouse_name" : "UPS_NEW" ,
"warehouse_created" : ISODate( "2014-12-12T07:12:10Z" )
}
)
EXPLAIN SELECT * FROM warehouse WHERE warehouse_id = 1 ;
QUERY PLAN
Foreign Scan on warehouse ( cost= 0.00 . .0 .00 rows = 1000 width= 84 )
Filter: ( warehouse_id = 1 )
Foreign Namespace: db. warehouse
( 3 rows )
ANALYZE warehouse;
DROP FOREIGN TABLE warehouse;
DROP USER MAPPING FOR enterprisedb SERVER mongo_server;
DROP SERVER mongo_server;