Question

If I perform the following update from my NodeJS app:

db.collection('test').update({name: 'some_name'}, {$set: {update_time: new Date()}}, {w:1}, function(err) {
  console.log('successfully updated');
});

I believe it will use the NodeJS app's clock, is there a way to use the database's clock instead?

Was it helpful?

Solution

Though I generally wouldn't recommend based on that your server times should be synchronized, you could use eval()

db.eval("function(){ return new Date() }", function(err, result) {
  console.log( result );
});

That basically sends the JavaScript function to the server to execute and returns the result.

Read the docs and use with caution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top