-
1. Re: How do I write ObjectId type field data to mongodb?
rareddy Feb 1, 2018 9:09 AM (in response to kevinyjn)The question is vague. You have not given any context of what you are doing? Give me an example and how you would like to see in MongoDB.
In Teiid with MongoDB as source, the Primary Key of the table maps to the "_id" field in MongoDB. If you do not have a Primary Key then MongoDB still creates one implicitly in document model. With MongoDB, to manage relations from Table A to Table B, they need to be designed as such and define related extension properties carefully. Read and understand from here [1]. If you already have a document model in MongoDB then try using metadata import feature to design to Table structure automatically.
-
2. Re: How do I write ObjectId type field data to mongodb?
kevinyjn Feb 1, 2018 12:35 PM (in response to rareddy)Ramesh,
Thank you for replying my question, the example is like bellow, the field parentid were referenced by _id, the front 4 rows were generated manually, these types of parentid were what I expected, but the bellow rows were generated by teiid, it becomes to string type.
The table defineation is :
Part of virtual procedure clause is:
LOOP ON (SELECT CommonSrcOrganization.GY_KSDM.KSDM, CommonSrcOrganization.GY_KSDM.SJKS FROM CommonSrcOrganization.GY_KSDM) AS ksrow
BEGIN
UPDATE GuanZhong.Organization SET parentId = (SELECT GuanZhong.Organization.id FROM GuanZhong.Organization WHERE GuanZhong.Organization.code = convert(ksrow.SJKS, string)) WHERE GuanZhong.Organization.code = convert(ksrow.KSDM, string);
END
-
3. Re: How do I write ObjectId type field data to mongodb?
rareddy Feb 1, 2018 1:03 PM (in response to kevinyjn)If the document is already in the MongoDB, then use
File -> Import -> Teiid Designer -> Teiid Connection >> Source Model
and point to the MongoDB database, and use translator mongodb and import metadata. That will generate correct metadata to begin with.
-
4. Re: How do I write ObjectId type field data to mongodb?
kevinyjn Feb 1, 2018 11:04 PM (in response to rareddy)Ramesh,
Thank you for pointing me the operation step, I've followed the step to import MongoDB metadata, but it effects the same as I manually created metadata, the field parentId were assigned with field "_id", but it was saved into hex string type instead of ObjectId type. I want to save it into ObjectId type so that out client developer can correctly access the data.
-
5. Re: How do I write ObjectId type field data to mongodb?
rareddy Feb 2, 2018 9:38 AM (in response to kevinyjn)How did you create a connection to MongoDB in the Teiid Server. When using the above procedure, the first step is to select or create a connection. There you need to create a MongoDB connection and use that. If there already connection based some other JDBC drivers Teiid does not support that. So, try creating a new connection and using that from Designer. Otherwise look into Teiid documentation here [1] on how to create MongoDB connection on the server without Designer and select the JNDI name during the import.
-
6. Re: How do I write ObjectId type field data to mongodb?
kevinyjn Feb 2, 2018 12:19 PM (in response to rareddy)Hi, Ramesh, I created the connection to MongoDB using mongodb translator, and I followed your step to import the source model, the ObjectId fields were imported as object type. but when I save the ObjectId field references from other ObjectId field using UPDATE clause, the updated ObjectId field value becomes hex string formation, I guess the ObjectId that referenced were convert into hex string by mongodb translator, I don't know what formation of ObjectId field were stored to mongo db, I'm thinking of a solution to convert the hex string type ObjectId field data into the right formation that would be saved to mongo db, will you please give me some suggestion to solve this problem?
Kevin
-
7. Re: How do I write ObjectId type field data to mongodb?
rareddy Feb 2, 2018 2:57 PM (in response to kevinyjn)According to my code I set the ObjectId as String [1], I am not sure how it is being converted to Object. You can try converting all the "_id" fields as String, and then set native type as "org.bson.types.ObjectId" and auto increment to true. If that does not work I would have debug and see why that is the case.
[1] teiid/MongoDBMetadataProcessor.java at master · rareddy/teiid · GitHub