neumino / reqlite

Reqlite - RethinkDB in JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reqlite does not support updating fields in nested documents

ShaggyDev opened this issue · comments

I have been writing tests utilizing Reqlite and connecting through Thinky which has been working great so far. Unfortunately I have run into a snag where it appears Reqlite does not support updates to fields nested within subdocuments. Any chance this is a toggle-able feature that I am missing or is this just not built in at the moment? I wrote a simple test case to illustrate the issue if it helps at all:

var Game = thinky.createModel('game', {
    id: type.string(),
    players: type.object().default({
        player1: {},
        player2: {},
    }),
});

describe('Test', function() {

    before(function(done) {
        var game = new Game({id: '1'});
        game.save().then(function(newGame) {
            console.log('New Test Game created: ', newGame);
            done();
        })
    });

    it('should update nested documents', function(done) {
        var updates = {
            players: {
                player1: {
                    connected: true
                },
                random1: true
            },
            random2: true
        };

        Game.get('1').update(updates).run().then(function(updatedGame) {
            console.log('Here is the updated game: ', updatedGame);

            assert.ok(updatedGame);
            assert.ok(updatedGame.players);
            assert.ok(updatedGame.players.player1);
            assert.ok(updatedGame.players.player1.connected);
            done();
        });
    });
});

Within the updates object, the field I am checking for in this test case is the player1.connected field. I inserted the random1 and random2 fields to demonstrate at what depth the updates are being recognized. In this test case, only the random2 field will successfully be recognized with the rest of the update being ignored.

If you try to get the document with a new query, what do you get?

Just after running the update, if I were to run a simple get query on that ID, I would get the same results where the subdocuments would not contain the updates. I did have that built into this test to test out if the response from the update was, for some reason, omitting the subdocument updates but removed it since it didn't reveal any clues.

Fixed in 2.2.10