MongoDB: output 'id' instead of '_id'

I am using mongoose (node), what is the best way to output id instead of _id?

Find all documents within last n days

My daily collection has documents like: .. { "date" : ISODate("2013-01-03T00:00:00Z"), "vid" : "ED", "san" : 7046.25, "izm" : 1243.96 } { "date" : ISODate("2013-01-03T00:00:00Z"), "vid" : "UA",...

how to use mapreduce in mongoose/mongodb query subdocument?

I implemented a simple message system in mongoose/mongodb, the schema is like the following var schema = new mongoose.Schema({ user: {type:String, required:true}, updated: {type:Date,...

Find last record of each day

I store data about my power consumption, each minute there is a new record, here is an...

Mongoose and new Schema: returns "ReferenceError: Schema is not defined"

I am creating a new sample application, where I try to connect to a MongoDB database through Mongoose. I create a new schema in my service.js file, but I get the following error when I run nodemon...

Mongodb aggregate by date with empty daybins

I am trying to do a per-day aggregation in MongoDB. I already have an aggregation where I successfully group the data by day. However, I want to do the aggregation in such a way where days with no...

Group by date intervals

I have a collection with documents like this: { datetime: new Date(), count: 1234 } I want to get sums of count by 24 hours, 7 days and 30 days intervals. The result should be like: { "sum":...

Get distinct ISO dates by days, months, year

I want to get a distinct set of years and months for all document objects in my MongoDB. For example, if documents have...

Aggregate $group for multiple date ranges

In my aggregate, each document in the stream will have a date on it. I need to sum some values over date ranges.. My documents look like: { value: 3, date: [SoME TIME STAMP] }, { value: 4, date:...

Get the size of all the documents in a query

Is there a way to get the size of all the documents that meets a certain query in the MongoDB shell? I'm creating a tool that will use mongodump (see here) with the query option to dump specific...

How to group documents by month?

I have a collection of transaction data in mongodb, like this: [ {timestamp: ISODate("2015-11-10T11:33:41.075Z"), nominal: 25.121}, {timestamp: ISODate("2015-11-22T11:33:41.075Z"), nominal:...

mongodb: query for the time period between two date fields

If I have documents in the following schema saved in my mongoDB: { createdDate: Date, lastUpdate: Date } is it possible to query for documents where the period of time between creation and...

Count documents by ignoring duplicates in array

Each appointment has some services. I want to find total count of appointments for each service. My document looks like this: [{ "appointmentTag":"xyz", "services" : [ { "name" :...

MongoDB get first and last document in aggregate query

How can I get first and last document based on time field. I can use $group and get $first and $last document, but I don't need grouping here, just get first and last full document. Maybe I could...

MongoDB: exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating

I created /data/db in root directory and ran ./mongod: [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db,...

spring-data-mongodb equivalent of @JsonUnwrapped in Jackson

I would like to use a composition pattern to reuse common portions of classes as I can do in Jackson with @JsonUnwrapped, without adding an extra level of structure in the mongodb document, for...

mongodb aggregate trunc date function?

worked with a bunch of other SQL databases before; like Postgres and...

Postman raw data works but form-data not works on POST request in node

I'm facing some problem when using postman. When I'll try to send raw data in JSON(application/json) format, it get success. Postman sending post request and succeded But when I'll try to send...

PostgreSQL with Django: should I store static JSON in a separate MongoDB database?

Context I'm making, a Django web application that depends on scrapped API data. The workflow: A) I retrieve data from external API B) Insert structured, processed data that I need in my PostgreSQL...

Update mongodb document, if the document exists, else create

So I am trying to make a discord bot for me and my friends for tracking stats in CS GO 10 mans, and I am using cheerio for webscraping from the site that provides us the stats, and then pass them...

Error Message: MongoError: bad auth Authentication failed through URI string

I'm trying to connect to my mongoDB server via the connection string given to me by mongo: "mongodb+srv://david:[email protected]/test?retryWrites=true" In my code I am calling...

Golang. MongoDB bulkWrite() to update slice of documents

I have a slice of objects I want to save to Mongo collection. Let's say type ( User struct { AccountId string Name string FamilyName string EmailAddress ...

Can not connect MongoDB docker-compose

Can not connect mongodb run in docker-compose MONGO_URL=mongodb://db:27017/500ae_cms error: MongoDB connection error: mongodb://db:27017/500ae_cms. MongoNetworkError: failed to connect to server...

MongooseError [MongooseServerSelectionError]: connection <monitor> to 52.6.250.237:27017 closed

I am trying to save data in mongodb through post method and using mongodb atlas with node.js but it keeps giving me an error, I provided correct connection string and correct password. Please help...

"Your filters contain a field 'status' that doesn't appear on your model definition nor it's relations" (Strapi)

https://strapi.io/documentation/v3.x/guides/draft.html#apply-our-changes I am customizing my own API, which of course I would like to filter only posts with status published, so I followed the...

MongoDB: Transform array of objects to array of arrays

I have a collection named "records" that contains documents in the following form: { "name": "a" "items": [ { "a": "5", "b": "1", "c": "2" }, { "a": "6",...

Write command args in kubernetes deployment

Can anyone help with this, please? I have a mongo pod assigned with its service. I need to execute some commands while starting the container in the pod. I found a small examples like...

Power BI - Lost connection to MySQL server at 'waiting for initial communication packet', system error: 10060

I'm getting this error message randomly on the power bi connector for MongoDB atlas. Last refresh failed: Mon Jan 25 2021 10:49:32 GMT+0800 (Malaysia Time) Unable to connect to the data source...

How to get collection of document from mongodb cursor?

I have the following code which should return a list of documents from mongodb. struct Vehicle{ id: String, name: String } pub async fn list_all() -> Vec<Vehicle>{ let mongodb =...

NodeJs/Express/MongoDb - ERR_HTTP_HEADERS_SENT

hope you spent really good holidays I'm following a tutorial online but i've an error that the teacher doesn't have in the video (i also copy his code but same error). I have this error only with...