Two issues i'm having importing data from a CFQUERY (odbc) to mongodb

44 views
Skip to first unread message

bbl...@jdsdesignonline.com

unread,
Feb 16, 2014, 8:49:42 PM2/16/14
to cfmo...@googlegroups.com
I posted this as a ticket in github before i'd found this group, so you can close that and i'll paste the content here


so, i've recently switched from the railo mongodb extension to cfmongodb because i'm having problems with my data landing in a proper mongodb format. I'm working on a routine which will perform a CFQUERY against a VisualFoxPro ODBC connection(barf), then stash the records in mongodb. the mongodb data will later be consumed by a nodeJS app (mongoose odm + angularJS) . 

two problems i'm having

1) i was setting _id to a particular field in my db, for example, the old db has a "drivernumber" field, so i was feeding that into _id because on the nodeJS side, mongoose ODM handles "joining" the data when needed. This field is essentially a string. Mongo's documentation seems to indicate anything is fine here, so long as its unique but you obviously loose the timestamp. It works in both the mongodb extension for railo and mongodb itself  but throws an error "invalid objectID".. Is that something i can work around with some modification?

2) this is the big one for me. I'm taking the cfquery results, iterating, converting to a struct (queryRowToStruct), performing any modify operations and then stashing it in mongodb. I'm still getting string values for everything. This could be more of a product of the ODBC connection, as i'm seeing a format like {ts'......'} (odbcdatetime?)    I've tried various javaCast and createObject(...javaDate..).init(mydate).. but its still landing as a string! further investigation indicates similar behavior is happening to ints as well.. Is it the fact that i'm converting to a struct? Also, can i feed a full query into some method in your wrapper?

any help would be great! i'm on the verge of just using epoch time, but i don't think that'll work quite right given the fact that it'd still be a string, mongo might not order it correctly..

Marc Esher

unread,
Feb 17, 2014, 3:10:03 PM2/17/14
to cfmo...@googlegroups.com
Hey there,

As for #1, that's a known shortcoming in cfmongodb. The ability to set a custom _id is not in there currently, and I don't know a good way to work around it without modifying cfmongodb to support that functionality

For #2, The last I worked with Railo (2 years ago maybe?), it seemed to correctly deal with numbers and dates, and so cfmongodb actually treats Railo as a special case and doesn't do any of its normal hocus-pocus with data typing. Try this:

In MongoUtil.cfc, go to line 32 and you'll see this function:

public function getDocumentTyperClass(){
if( server.coldfusion.productname eq "Railo") return "net.marcesher.NoTyper";
return "net.marcesher.CFStrictTyper";
}

Comment out that "if" statement, then reinit your application and try again. That *should* fix the number problem. However, it won't have any effect on the dates because cfmongodb doesn't have any provision for that... it only applies datatype operations to numbers and booleans. In Adobe CF, dates "just work" for me. For example, if I run localhost/cfmongodb/examples/gettingstarted.cfm I see that timestamps created with now() correctly show up as Dates in mongo, i.e. 

> db.people.findOne()
{
        "_id" : ObjectId("530261df2fa08d7479920d77"),
       ...
        
        "MODTS" : ISODate("2014-02-17T19:24:15.814Z"),
        "TS" : ISODate("2014-02-17T19:24:15.007Z")
}
> new Date()
ISODate("2014-02-17T19:27:17.461Z")


If I CFDump that same object in CF-land, I see this form: {ts '2014-02-17 15:08:54'}

Perhaps you'll need to take up the date thing with the Railo people.

Marc



--
You received this message because you are subscribed to the Google Groups "CFMongoDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cfmongodb+...@googlegroups.com.
To post to this group, send email to cfmo...@googlegroups.com.
Visit this group at http://groups.google.com/group/cfmongodb.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages