0
db.company.update(
{"company": {$in:[
    "1744",
"FILMS"
    ]}},
{$set:{"is_deleted": true}},
{"multi": true}
)

I want to convert this mongo shell into nodejs script, Now I am not sure how do i do this? can someone help me with this? Like I want to do this query with help of nodejs script

3 Answers3

0

You can try for the following:

var MongoClient = require('mongodb').MongoClient      
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

 db.company.update({"company": {$in:["1744","FILMS" ]}},
     {$set:{"is_deleted": true}},
    {"multi": true}
   )
});
Subburaj
  • 5,114
  • 10
  • 44
  • 87
0

MonogoDB provides drivers to connect your application to database. You can use mongodb driver for nodejs to query your database. nodejs driver mongodb

0

You can try using some ODM such as mongoose to execute this query in nodejs environment. Basically ORM's are used to create an object and map it to a query to be executed for fetching data from the database. This provides a more cleaner approach without any hassle, as you deal with javascript objects and not the actual query itself

For example, for a simple query in mongodb shell:

db.users.find({"name":"Sam"})

can become the following using an ODM like mongoose:

const User = require('../models/user');  // assuming that you have schema defined
user = new User("Sam", "Billings"); // create an object
User.find({"name": "Sam"}, callback); // run the query

You can read about mongoose docs in this link.

Aquib
  • 145
  • 1
  • 11
  • Is it really solve the problem of the question?? Also where does `ORM` come into play here?? – Subburaj Dec 18 '19 at 07:08
  • I agree, the question is limited just to converting this query(which is your solution). The other way from writing the query itself is to use ORM's that make it easier to work with MongoDb itself. I am just suggesting, thanks! – Aquib Dec 18 '19 at 10:29