Hi,
I eventually managed to resolve this but I'm not 100% sure I understand why.
Initially I had implemented the following query in the view.on('init', function(next) {... of /routes/views/me.js.
----------------------
User.model.findOne ()
.where ('key', locals.user.key)
.populate ("language")
.exec (function (err, languages) {
if (languages) {
locals.user.language = languages.language
} else {
console.log ("NOTHING");
}
});
----------------------
This seemed to create some kind of race condition where occasionally, but infrequently, the mongoose updates would actually contain the correct, updated data, and it would be committed correctly to mongodb. Most of the time however, it just 'succeeded' with the query, but using the original data - despite the logging info indicating otherwise (see my initial post). In effect, nothing changed.
After reading more of the code and documentation, I tried moving this logic into /routes/middleware.js :
----------------------
/**
Make languages universally available
*/
exports.loadLanguages = function(req, res, next) {
keystone.list('Language').model.find().exec(function(err, languages) {
if (err) return next(err);
req.languages = languages;
res.locals.languages = languages;
next ();
});
}
----------------------
and then calling this from /routes/index.js
----------------------
keystone.pre('routes', middleware.loadLanguages);
----------------------
Then I load this into an AppData global in the following the SydJS site example: AppData.langauges = !{JSON.stringify(languages)}; where it can be accessed by my React component and loaded into react-select.
After this, there appear to no longer be any race conditions, and both submission/update and display work consistently in the sense that changes are correctly sent, correctly pushed to mongo, and persisted across the app.
This is probably not the most optimal solution - especially since there is not really a need to make this data available globally, but I wanted to share it, if only to possibly receive an explanation about the race condition, and maybe save someone else a bit of time if they stumble upon similar behavior!