I use express.js with mongoose as ODM.
I know mentioned that when other serives do an update to mongoDB, mongoose doesn't recognize this. So still shows the old state of the database.
I think this is because mongoose uses a callback to get updated after creating, updating a new document but this callback doesn't get fired when another service interacts with mongoDB.
So how can I manuelly say mongoose to look after not own created documents?
routes/user.js
var User = require('../models/user.js')
, requirements = { enabled: true, expired: false, locked: false };
exports.list = function(req, res){
User.find(requirements, function(err, users){
res.send(users);
});
};
app.js
app.get('/users', user.list);
When I now access /users with curl or with the browser I am getting an array of all users in mongodb. Thats right until now. Now I register a new user over my PHP environment. When I now request /users again I still get the same array as before without the over php created user!
When I now restart the node service and request /users again the by php created user is there....
The express.js framework includes view caching which is enabled by default for production sites). I suspect your results are getting cached because you have included a function reference (user.list) rather than a closure, eg:
app.get('/users', function(req, res){
User.find(requirements, function(err, users){
res.send(users);
});
});
The view caching is a global setting and should only be caching the view template, not the contents of the view. There was a request for more granular caching but it looks like this isn't required.
You can try disabling the view caching using:
app.disable('view cache');
A good resource to search or ask for clarification would be the Express.js Google Group.