As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
Trouble with modules.collectionAccess for a custom endpoint
D
Dave Ackerman
started a topic
over 9 years ago
Hey there,
I'm trying to create a custom endpoint that runs a series of mongo queries. I seem to have the pattern right, but for some reason I cannot pull (find()) objects out of my collection with a query. Here's what I've got:
The whole objectID component in Mongo can be a bit finicky, depending on how the data was written. For the line where you define kickstartTemplateId, try any of the following:
var kickstartTemplateId = modules.collectionAccess.objectID(kickstartTemplates[0]._id);
var kickstartTemplateId = kickstartTemplates[0]._id.toString();
var kickstartTemplateId = kickstartTemplates[0]._id;
var kickstartTemplateId = modules.collectionAccess.objectID(kickstartTemplates[0]._id.toString());
Let me know if the results change with any of these options.
D
Dave Ackerman
said
over 9 years ago
Jeez, that code got butchered. Here it is in a gist instead:
Dave Ackerman
I'm trying to create a custom endpoint that runs a series of mongo queries. I seem to have the pattern right, but for some reason I cannot pull (find()) objects out of my collection with a query. Here's what I've got:
function onRequest(request, response, modules){
// fetch all of our kickstart-tpls
modules.collectionAccess.collection('kickstarts-tpl').find({}, function(err, kickstartTemplates) {
// we need to convert the string to an ObjectId representation??? I've tried it without
// this and it still returns nothing.
var kickstartTemplateId = modules.collectionAccess.objectID(kickstartTemplates[0]._id);
modules.logger.info('kickstart_tpl_id: ' + kickstartTemplateId);
// "kickstart_tpl_id: 53220be7f811291203033885"
modules.collectionAccess.collection('topics-tpl').find({ "kickstart_tpl_id": kickstartTemplateId }, function(err, topicTemplates) {
response.body = topicTemplates; // [ ]
response.complete(200);
});
});
}
The screenshot of my "topics-tpl" collection, which clearly matches that "kickstart_tpl_id":
http://dl.dropbox.com/u/68704/Screenshots/~d~d.png
There must be something wrong with my Mongo query, but I'm just not too familiar yet. Appreciate the help!