Welcome
Login
Sign up
Home
Solutions
Forums
How can we help you today?
Enter your search term here...
Search
Login
or
Signup
to submit a new ticket
Check ticket status
Start a new topic
Discussions
Kinvey Forums
Business Logic
Return all users
G
Gary W
started a topic
over 6 years ago
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 -- []`
3 Comments
Oldest First
Popular
Newest First
Sorted by
Oldest First
G
Gary W
said
over 6 years ago
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();
});
}`
P
Pete
said
over 6 years ago
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
G
Gary W
said
over 6 years ago
Thanks Pete, I'll try that.
Login
or
Signup
to post a comment
More topics in
Business Logic
How do I access query string values for GET and DELETE requests?
Basic Authentication in Business Logic
How do I cascade delete entities from related collections?
All BL failing with Violation Error
How do I send push notifications?
Whenever I try to query by _id, I get zero results
receiving SOCKETTIMEDOUT when requesting external http response
Unique Constraints on a collection column?
Need some help with grouping
Accessing Endpoint from Collection Hook
See all 342 topics
Gary W
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 -- []`