- preview post MongoFDW to AgensGraph 1 : https://jhs9396.github.io/2018-12-19-post1/ —-
3. MongoFDW SERVER CREATE
- if you succeed the mongo_fdw extension, next step is creating ‘mongo_server’.
CREATE SERVER mongo_server FOREIGN DATA WRAPPER mongo_fdw
OPTIONS (address '127.0.0.1', port '27017');
- mongo_server : server name. server name is possible customizing.
- (e.g mongo_server -> m_server, test, test1, mongo, etc…)
- mongo_fdw : extension name.
- address : host address
- if MongoDB is installed remote OS, 127.0.0.1 -> host address texting
- port : host port
- MongoDB default port is 27017. enter current port texting.
3-1. MongoFDW to AgensGraph(A.G) USER MAPPING
CREATE USER MAPPING FOR test SERVER mongo_server;
- test : AgensGraph user(role) name.
- if you don’t know user, in AgensGraph console, enter the ‘\du’
- mongo_server : mongoFDW SERVER name
- MongoFDW SERVER is used AgensGraph user(role). need a user mapping.
3-2. Creating AgensGraph(A.G) Foreign Table for MongoDB
CREATE FOREIGN TABLE IF NOT EXISTS public.c_table1
( name TEXT )
SERVER mongo_server OPTIONS (database 'test', collection 'collection1');
- public.c_table1 : foreign table name
- name TEXT : foreign table column. MongoDB document data(JSON) key is table column. column type is TEXT
- mongo_server : MongoFDW SERVER name.
- ‘test’ : MongoDB name
- ‘collection1’ : test MongoDB collection name
4. RESULT
- MongoDB data is three keys and three values
- {name : test}, {name : test1}, {name:test2}
- AgensGraph foreign table ‘SELECT’. It is possible to write with the SQL that you know
(If there are two or more tables, JOIN is possible.)
SELECT * FROM public.c_table1;
** If you is created(modified) foreign table by SQL query, Avoid creating, modified. Foreign table is using only for SELECT purposes. if you modified, need to ‘foreign table to materialized view’