I am trying to learn databases and nodejs.
I want to ask how can I translate the following from mongod to postgresql using nodejs.
//fill QueryString
collection.find({"myID" : {$in:QueryString} },{}).toArray(function(err, Stuff) {
.....
if ( .... ) {
collection.update(
{ "myID" : req.body.id },
{$set : { "myField" : req.body.fileid }},
function(err, resultNew) {
..
}//end of update
}//end of find
I tried :
//fill QueryString
for (var i=0; i<req.body.my_ids.length; i++) {
QueryString[i] = req.body.my_ids[i];
}
pg.connect(conString, function(err, client, done) {
if (err) return console.error('error fetching client from pool', err);
client.query("SELECT FROM mytable WHERE myID = ANY array_to_string(QueryString::int[],', ') ", function(err, Stuff) {
....
client.query("UPDATE mytable WHERE myID = 'req.body.id' SET myField ='req.body.fileid' " , function(err,result) {
});//end of update
}); // end of select
I am not sure my translations.
In the first query when using mongo , the "Stuff" will be an array and I have to do some calculations with it, but in node-postgres?Will it be an array ,or I have to specify something?Right now I can't find the appropriate syntax to search in QueryString.
In the second query I am not sure at all if it is right,or how can I write it.