-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert.js
33 lines (32 loc) · 996 Bytes
/
insert.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var uuid = require('uuid');
var ThinkTransaction = require('../thinkTransaction');
var transOptions = {
timeout: 30 //timeout the transaction if it couldnt complete within this time window
};
//Insert New User into Profile Collection
ThinkTransaction.begin(transOptions)
.then(function(trans) {
trans.op.insert({
Profile : { // Profile is name of your collection in rethinkdb database
id : uuid.v4(), //REQUIRED : You will need to explicity pass id value along with other attributes of the document
type: "User",
firstName : "John",
lastName : "K"
}
})
.then(function(results){
console.log('insert commit handler');
trans.commit().then(function(result){
console.log('commit complete');
console.log(result);
})
})
.catch(function(err){
console.log('insert catch handler');
console.log(err);
trans.rollback().then(function(result){
console.log('rollback complete');
console.log(result);
});
});
});