Start a new topic

Find the 1st match in a collection ? [Bug report]

I have a collection "Clients", which contains deviceID column. I have on it a record "ABC12345".

The follow code does not works ( does not finding any match.

Please Help.



function onRequest(request, response, modules)

{

var objectFound;



var findPatern = { "deviceID" : "ABC12345" };



var db = modules.collectionAccess.collection('Clients');



db.findOne( findPatern,

function( error, retrievedEntity )

{

if( error )

{



return response.error(error);

}



if( retrievedEntity === null )

{

return response.error('No matching entity found.');

}

else

{

response.body = retrievedEntity;

response.complete(200);

//objectFound = retrievedEntity;

}

}

);

}

Hi Yordan,



How is the deviceID populated? Is it based off of the _id of another collection? If so, you may need to convert your string into an objectID as follows:



```

var findPatern = { "deviceID" : collectionAccess.objectID("ABC12345") };

```



Also, make sure your case matches for both the key and the value of your findPattern query. For example, if the actual collection attribute name is deviceId, or deviceid, your query pattern will find zero records. The same is true for the value. ABC12345 is different than abc12345.









deviceID is just a name, it is not foreign key or something.

It's populated with just a text like "Nokia3510".
Can you paste in the entity that contains deviceID = 'ABC12345'?

I am not sure what You are asking for.

Please explain.
Specifically, can you provide the actual data record from the collection that contains the info you are searching on, as well as the actual query object.
I did. Everything above is the real code, with a real test string.
Yordan,



What I'm specifically looking for is to see what the record that this query condition looks like.



```

var findPatern = { "deviceID" : "ABC12345" };

```



Can you query the record through the API Console and paste the results here?
Actually seems like it is related to another unreasonable issue, i've just posted question on.
Login or Signup to post a comment