Is RethinkDB useful for partially updating json documents on rfc6902?

Share your experience with partially updating your JSON document. I now store my JSON documents in MongoDB, which looks like this:

  id: ObjectId(507f191e810c19729de860ea),
  title: 'Sterling Archer',    
  comments: [
    {text: 'Comment text', tags: ['tag1', 'tag2', 'tag3']},
    {text: 'Comment test', tags: ['tag2', 'tag5']}


I need to update my docs frequently using rfc6902 . Now I'm not optimized, which looks like this (I'm using nodejs / express / mongoose and fast-json-patch module in this example):

var jsonpatch = require('fast-json-patch');

app.patch('/document/:id', function (req, res, next) {
   var document_id =;

   // req.body.patch: { "op": "add", "path": "/comments/2", "value":  {text: 'Comment test3', tags: ['tag4']}" }
   var patches = req.body.patch; 

   // find document
   Document.findById(document_id, function (err, document) {
       // Applying patches
       jsonpatch.apply(document, patches);

       // Update whole document in MongoDB
       Document.update({_id: document_id}, document, function (err) {
           return res.status(200).send(); 


This does not optimize the approach to patch files due to two queries in MongoDB and replaces the entire document. So I am looking for an optimized approach and want to try RethinkDB for this task. Can you help me test if an atomic document can be updated using a single query from RethinkDB? Or should I be looking for another way to solve my problem?

Please share your experience with partially updating the JSON document.


source to share

1 answer

You only need one request to RethinkDB. Suppose you want to update the document ID 1

with the values ​​{foo: 1, bar: 2} and increase the "count" field, you would do

r.table("data").get(1).update(function(doc) {
    return doc.merge({foo: 1, bar:2, count: doc("count").add(1) })


Although this update requires a unique request, the entire document will be updated. If you have large documents, you can split them into multiple tables and later perform joins to retrieve the data. You may be interested in reading this article on data modeling:



All Articles