Secure write from mongodb shell

How to make a "safe" record that is immediately flushed to disk from javascript? I would like to be able to do this both from the shell and from the "CRUD" JavaScript stored procedure. This is just a question:

db.foo.insert({stuff: "yes", meta: "physics"});
db.runCommand( "getlasterror" ) ;

Vicki is unclear.

+3
source share
1 answer

Yes, you would use the Last error , but you need to set the fsync flag (and / or the replication parameter , depending on your definition of "safe"):

# force fsync
> db.runCommand({getlasterror:1,fsync:true})

# wait for replication to one other server (w = 2)
> db.runCommand( { getlasterror : 1 , w : 2 } )

, fsync . "" ( ). ( , , ).

+3

Source: https://habr.com/ru/post/1762387/


All Articles