Start a new topic

Return all users

Hi,



This is my endpoint so far.



What do I need to put in the find to return all users?



`function onRequest(request, response, modules) {

var collectionAccess = modules.collectionAccess;

collectionAccess.collection('user').find( { "_id": { $gt: "0" } } , function(err, user) {

response.body = user;

response.complete();

});

}`



Currently when testing it the response is this:



`200 SUCCESS -- []`

Hi Gary,



You try using the [`$exists` operator](http://docs.mongodb.org/manual/reference/operator/query/exists/)...



```javascript

function onRequest(request, response, modules) {

var collectionAccess = modules.collectionAccess;

collectionAccess.collection('user').find({ "_id": { "$exists": true } }, function(err, users) {

// Bob's your uncle!

response.body = users;

response.complete();

});

}

```




1 person likes this
I think I figured it out.



This seems to work but my guess is it's not the preferred way.



`function onRequest(request, response, modules) {

var collectionAccess = modules.collectionAccess;

collectionAccess.collection('user').find( { "_id": { $gt: collectionAccess.objectID("000000000000") } } , function(err, user) {

response.body = user;

response.complete();

});

}`
Thanks Pete, I'll try that.
Login or Signup to post a comment