robbiblubber.org

help | login | search:  
>>

read  source  history 


replaceOne()


MongoDB Driver Function Reference


Replaces a single document based on the specified filter.
More information can be found in the corresponding entry of the MongoDB Manual.



<collection>.replaceOne(<filter>, <replacement>[, <options>])



Arguments


<collection> The target collection.
<filter> A filter expression using query operators.
<replacement> A BSON document to replace the document.
<options> A BOSN document specifying options.



Options


{ projection: <document>, upsert: <boolean>, maxtime: <long>,
collation: <document>, hint: <document> }

projection Defines a subset of fields to return.
upsert Toggles an upsert.
maxtime Specifies a time limit in milliseconds.
collation A document specifying the collation.
hint A document specifying a hint.



Return Value


Returns a result set (cursor).



Example


db.employees.replaceOne({ salary: { $gt: 700000 }}, { name: "Roo", firstname: "Kanga", age: 20, salary: 100000 });


replaces the first document from the employee collection with a salary greater than 700000.




home | MongoDB Driver Function Reference | MongoDB Driver