Good morning Art,
The findOne function is a part of the collectionaccess module.
http://devcenter.kinvey.com/rest/reference/business-logic/reference.html#collection-access-module
An example of a call using it may look like this:
modules.collectionAccess.collection(collectionName).findOne({_id: reqBody[item]._id}, function(error, doc)
Thanks,
Art
Hello,
here is a part of endpoint script
Assuming that
- requestedIds is a collection of object ids that should be fetched. Let's assume it was initialized with ["SNWHotspot1", "SNWHotspot2"]
- UpdateResponse is a function that updates responseInt string array that whould be printed to response at the end of the process.
- reqBody is a request body object
var calls = [];
requestedIds.forEach(function(name){
UpdateResponse(EnumStatus.SUCCESS, "Within forEach");
calls.push(function(callback) {
UpdateResponse(EnumStatus.SUCCESS, "Within push");
var collectionName = <some existing or non-existing collection name>;
UpdateResponse(EnumStatus.SUCCESS, "findOne.id: " + reqBody[name]._id);
db.collection(collectionName).findOne({_id:reqBody[name]._id}, null, function(error, doc) {
UpdateResponse(EnumStatus.SUCCESS, "Within findOne");
if (err)
{
UpdateResponse(EnumStatus.ERROR, "push with error: " + err.message);
return callback(err);
}
UpdateResponse(EnumStatus.SUCCESS, name + "checked");
callback(null, name);
});
});
});
UpdateResponse(EnumStatus.SUCCESS, "Calls count: " + calls.length);
modules.async.parallel(calls, function(err, result) {
UpdateResponse(EnumStatus.SUCCESS, "Within parallel");
if (err)
return UpdateResponse(EnumStatus.ERROR, "Result with error: " + err.message);
UpdateResponse(EnumStatus.SUCCESS, result);
});
response.body = JSON.stringify(responseInt);
response.complete(200);
Fot the following input:
{
"SNWHotspot1" :
{
"_id" : "SNWHotspot1",
"somefield1" : 1,
"someOtherField1" : 2
},
"SNWHotspot2" :
{
"_id" : "SNWHotspot2",
"somefield1" : 3,
"someOtherField1" : 4
}
}
this code with responses with:
200 SUCCESS -- "{\"status\":true,\"message\":[\"requestKey: SNWHotspot1\",\"requestKey: SNWHotspot2\",\"Within forEach\",\"Within forEach\",\"Calls count: 2\",\"Within push\",\"findOne.id: SNWHotspot1\",\"Within push\",\"findOne.id: SNWHotspot2\"],\"error\":[]}"
As you can see there is no call or no callback to/from findOne function.
Any idea why?