db.users.updateOne(
{
userName: "username1",
someAdditionalID: 12345,
},
{
$push: {
userDataArray: {
name: "updated name",
description: "updated desc",
},
},
$setOnInsert: {
userName: "new username",
someAdditionalId: 478326,
},
},
{
upsert: true,
}
);
var sameLogins = Users.findOne({ login: "a" }, (err, user) => {
if (err) console.log(err);
console.log(user);
});
var sameLogins = Users.findOne({ login: "a" })
.then(user => console.log(user))
.catch(err => console.log(err));
Return Date as Date Object
The mongo shell wrap objects of Date type with the ISODate helper; however, the objects remain of type Date.
The following example uses new Date() to return Date object with the specified UTC datetime.var myDate = new Date("2016-05-18T16:00:00Z");
app.get('/', function(request, response) {
response.render('pages/index', { regions: regionsController.getAll() });
});
let regionsModel = require('../models/regions');
exports.getAll = function(request, response) {
regionsModel.getAll(function(error, docs) {
if (error) {
console.log(error);
return response.sendStatus(500);
}
response.render('pages/index', { regions: docs });
});
};
const controller = require('./controller');
app.get('/', function(request, response) {
controller.getAll(request, response);
});