skip to Main Content

How to return raw JSON directly from a mongodb query?

In MongoDB (using mongosh or command-line mongo cli), you can query documents, for example using db.mycollection.find({"something":true}) and get the following result: { "someDate": ISODate("2022-10-24T17:21:44.980Z"), "something": true, "hello": "world" } This result, however, is not valid JSON (Due to ISODate). How…

VIEW QUESTION

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
Back To Top
Search