Whenever I try to query by _id, I get zero results
M
Michael
started a topic
over 7 years ago
When querying using Business Logic's collectionAccess module by the _id field, zero results are returned. Yet when I run the same query via the REST API, I get a result back.
2 people have this question
1 Comment
M
Michael
said
over 7 years ago
The reason that you cannot find your record is that the _id stored in the database is not a string, but rather a BSON object. The query in the REST API automatically does this conversion, but the collectionAccess module in business logic gives you raw access to the database. We've provided a helper function in collectionAccess, objectID, to convert a string to a BSON object. So in order to run your query, you should first convert it using the `objectID` method.
var bsonID = collectionAccess.objectID(request.body._id);
For example:
function onRequest(request, response, modules){
var collectionAccess = modules.collectionAccess;
var myID = collectionAccess.objectID("51756c8f3e3b484004023792");
Michael
2 people have this question