rethinkdb Getting started with Node Insert a document into a table


Example

r.connect({host: 'localhost', port: 28015})
.then((conn) => {
    return r.db("stackoverflow").table("examples")
        .insert({
            // If `id` is not set, will automatically generate a UUID
            id: 1,

            name: 'Thinker',

            // Will translate Date types.
            creationDate: new Date(),

            // Embedded array
            tags: ['rethinkdb', 'rethinkdb-javascript', 'rethinkdb-python'],

            // Will evaluate `r.now()` using server time
            dateWithServerTime: r.now(),

            // Embedded document
            location: {
                // Using geospatial example
                coordinates: r.point(-122.423246,37.779388),
                name: 'San Francisco'  
            },
        }).run(conn);
}).then((result) => {
    // Returns results object which includes array of generated UUIDs 
    //  for inserted documents
    console.log(result);
});