I've set up an Informix 12.10 Innovater-C (free version) database. I've connected a Meteor/Mongo app remotely to it using the Informix mongo wire listener.
I've created a table with the following structure:
hashtags MULTISET(VARCHAR(255) not NULL),
fullcomment VARCHAR(255),
url ROW(hostname VARCHAR(255), link VARCHAR(100))
I can insert rows using sql (e.g. using dbaccess), and they show up in meteor perfectly, with the hashtags being an array of strings, and url being an object. An example object returned would be:
{ hashtags: [ 'xyz', 'abc' ],
fullcomment: 'this is comment',
url: { hostname: 'www.google.com', link: 'link' }
}
However, in Meteor, I can't insert rows using the usual collection.insert() syntax. As long as I'm inserting a field containing only simple datatypes (i.e. no sets and no rows) then it works. For example, in the above defined table, I can do collection.insert({fullcomment: "comment"}) which will work and leave the other fields null.
When I try to insert a document with a url object with the following statement:
clips.insert({
fullcomment: "this is comment",
url: {hostname: "www.google.com", link: "xyz"}
});
I get the following error:
MongoError: Unable to insert into table testclip3: -9634 No cast from bson to ROW(hostname varchar(255), link varchar(100)). | No cast from bson to ROW(hostname varchar(255), link varchar(100)). (SQL Code: -9634, SQL State: IX000)
Similarly, if I try to insert a hashtags field containing an array, I get:
MongoError: Unable to insert into table testclip2: -9634 No cast from bson to MULTISET(char(255) not null). | No cast from bson to MULTISET(char(255) not null). (SQL Code: -9634, SQL State: IX000)
Am I doing something wrong with my table setups? Or is there a way I can specify the appropriate cast on the server side? I'm trying to keep the Meteor/Mongo side untouched if possible so I can transition an application over from Mongo to Informix.
The alternatives I see would be:
- Use a BSON column in Informix to store the JSON documents natively. This works, but I'd really like to use native columns so that I can set up parent/child relationships, etc. like normal relational tables. This is mitigated by the fact that Informix allows you to construct views from JSON fields, but it seems that it'd be easier to try to keep a normal table structure as much as possible
- Use SQL on the Meteor side to insert documents. This would be a real pain, as it would involve manually unwinding and translating objects into the appropriate fields, which I'm hoping to avoid.
Anyway, thanks for any insights or suggestions you might have.
Aucun commentaire:
Enregistrer un commentaire