I have in my file server.js this code:
MongoClient.connect(url).then(db => {
app.use('/users', service({
Model: db.collection("Users"),
}));
});
Now if i open "/users" all my users are displayed. I want to create service to give me one user by its Id . when i visit "/users/5" will give me the user who his id=5. Please who can help me ?
This is already built in. MongoDB uses ObjectId in _id
. So if you take any _id
property from the /users
list and open /users/<_id>
it will show that specific user.
For more information see the basics guide, the services API (and how those map to a REST API) as well as the database adapter common API and the MongoDB adapter documentation.