The version of orientdb is 2.2.11 and we are using the below code: 

> var OrientDB = require('orientjs');
>> var json2csv = require('json2csv');
>> var fs = require('fs');
>> var os = require("os");
>> var server = OrientDB({host: '10.xxx.xx.xx', port: 8004});
>> var db = server.use({name: 'gims_instance', username: 'root', password: 
>> 'root',useToken:true});
>> console.log("Started Live query")
>>
>> var fields = 
>> ['@type','@class','category','question','flag','sme_update','loggedtime','answer','user']
>>
>> var input = JSON.parse(fs.readFileSync('file2.json', 'utf8'))
>> var csv = json2csv({ data: input.result,fields:fields});
>> var dir='Output1.csv'
>> var flag=0
>>
>> function statPath(path) {
>>   try {
>>     return fs.statSync(path);
>>   } catch (ex) {}
>>   return false;
>> }
>>
>> var exist = statPath(dir);
>> if(exist && exist.isFile()) {
>> console.log('inside if')
>>  flag=1
>> }
>> else if (flag==0){
>> console.log('inside elif')
>> fs.writeFile('Output1.csv', csv+os.EOL, function(err) {
>>   if (err) throw err;
>>   console.log('file saved');
>> });
>> }
>>  
>> db.liveQuery("live select from training")
>>   .on('live-insert', function(data){
>>      //new record inserted in the database,
>>      var myRecord = data.content;
>>      // your code here...
>> console.log(myRecord)
>> var csv = json2csv({ data: myRecord,fields:fields,hasCSVColumnTitle: 
>> false});
>> console.log(csv)
>> fs.appendFile('Output1.csv', csv+os.EOL, function(err) {
>> if (err) throw err;
>> console.log('file saved');
>> });
>>   })
>>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to