skip to Main Content

Mongodb – got and error when i connect mongo db to nodejs

```const timeoutError = new error_1.MongoServerSelectionError(Server selection timed out after ${serverSelectionTimeoutMS} ms, this.description); .MongoServerSelectionError: connect ECONNREFUSED ::1:27017 const {MongoClient}=require('mongodb'); const url='mongodb://localhost:27017/'; const client= new MongoClient(url); const dataBase= 'nodejs'; async function getdata(){ let result= await client.connect(); console.log('connect to server') let db= result.db(dataBase)…

VIEW QUESTION

MongoDB – Query same collection twice

I have a posts collection and I want to return the latest posts and featured posts with 1 query. post document sample { "title":"Hello World", "author":"Bob Paul", "featured":True, "published":True, "created_at":"2019-01-15 10:27:16.354Z" } This is what I want returned: { "latest":…

VIEW QUESTION

How to delete items by _id using mongodb

I have a problem trying to delete data by providing an array of id's (got error). I guess it has something to do with ObjectId. Could you help me fix it? User.deleteMany({ _id: { $in: ['638207a8b9ebc3ea8f276684', '63823ffe310abc61b4ee11a0', '63822a71319517d196af6d59' } })…

VIEW QUESTION
Back To Top
Search