good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
MongoDB ObjectIDby betacentauri (Sexton) |
on Oct 12, 2019 at 17:36 UTC ( [id://11107380]=perlquestion: print w/replies, xml ) | Need Help?? |
betacentauri has asked for the wisdom of the Perl Monks concerning the following question: O monks, I can't for the life of me figure out the proper way to prepare HTML references to MongoDB documents. I'm using Dancer2 with MongoDB 3.4.15, and Template Toolkit. I'm fairly new to these three monsters, and it shows. I can select and display documents from a collection in an HTML table. When a table row is clicked, I want to show a modal window filled with the document data, then possibly edit some data, then possibly save it back. My problem lies in how to build the table. I envision every row provisioned with an onclick script which receives the document _id and uses it as a key to bring the document from the database via AJAX for the modal to be filled. Now, how to go about presenting _id, which is an ObjectID, to Template Toolkit as valid HTML content for the script to consume it? As per Data::Dumper, each _id field data is '_id' => bless( {'oid' => '...funny characters...' }, 'BSON::OID' ). Understandably, I can't seem to make any other than HASHrefs to reach my HTML. Should I serialize every ObjectID on the way to HTML, then deserialize it to get an ObjectID again? How to achieve this? If I were to extract oid, then convert it to some visible form, could this be done into the template? I've tried with a $project stage in the aggregation pipeline but I don't understand how or where to convert oids to strings. Am I misdirected? Is there a simple way to do this? Thank you in advance.
Back to
Seekers of Perl Wisdom
|
|