Category "aggregation-framework"

Mongodb: Merge nested objects based on common identifier

I have 3 objects like this {"_id":{"$oid":"625f0e73b1d7269de9ebdaeb"}, "Type":"scalar", "Temperature":22.79, "Vibration":{"A-P2P":{"X":85},"Z2P":{"X":43},"Crest

MongoDB Atlas Search Stage for newsfeed with GoogleRating, CurrentDate, LikeCount & CommentCount

I'm working on social media platform and I need to fetch posts for newsfeed with mongodb search query. currently I'm using dynamic index on my post collection,

Query with arbitrary number of filter conditions that come from querying the same collection

const score_schema = mongoose.Schema( { tester_id: { type: mongoose.Schema.Types.ObjectId, ref: "user", required: true, }, test_

MongoDB, get documents by a field, and mergeObject from another collections grouped count

Okay, the title is a bit too verbose and complicated but I have no idea how to put it any better. So here's what I have ModelA ModelB that has reference to Mode

How to fill missing field values with linear interpolation?

I have a collection of documents representing values at specific dates. Some of those dates don't have a value (the field can be missing or set to null). I'd li

$geoWithin return document located outside the polygon queried

I've recently came across this behaviour that I cannot explain. $geowithin return documents outside the polygon queried. To illustrate my problem, I've made a m

find customers in zip code using mongodb aggrigation

I have 2 mongodb documents shop and customer shop documents are like below { id: 1, zipcodes:[ '12345', '11111', ] } { id:2, zipcodes:[ '45678', ]

How to filter data in collection containing documents with 3 level nested arrays depending on the values in the first and last nested array mongo

I appreciate any help in such case. Collection in MongoDB (now only 4 documents for demonstration purpose): { "_id" : ObjectId("62684847e9594c65cbaa5d85

Insert data with new fields OR update conditionally using updateOne mongodb

I have a document with format like this: { "f1": "v1", "f2": { "id": 1, "sub": "subv", "updatedAt": 123 } } I have an another source that

MongoDB get sum of fields which I have modified in the project pipeline

I want to calculate avgAmount as the sum 3 fields = [balanceLoaded + operatorDueAmount - walletUsage]. But these fields can either be zero or themselves (balanc

How to find Distinct No of Document on specific field MongoDB and Implement in Java

I have data and need to group by two fields and in response display unique filed along with the count on this field. Sample data: [ { "categoryCode":"c

Casting an object within a MongoDB document to date time within a filter definition builder

I am hoping someone can help me as I am new to Mongo DB or point me to a work around, I have a property within a Mongo DB document which is of type object, but

Unwind object array but preserve its parent

I want to unwind some data, but preserve the parent. I am getting the whole flattened objects, but missing the first one. I want to keep that one. How can I do

MongoDB Group by field, count it with condition

I would like to count different hu for a shipment. So I write this query but how I can count different hu group by shipment ? my query : db.eventstranslated.agg

MongoDB - How to bring age group data

How to bring age group base data from a collection in MongoDB i.e how many people are 0-18, 19-24, 25-34, 35+ [ { "_id": ObjectId("608be7c608c7de2367c8963

Mongoose and MongoDB - Get all countries and users associated with country

So I have a list of posts data that looks like this: [ {user: 'Bob', country: 'USA'} {user: 'Kim', country: 'Mexico'} {user: 'Darren', country: 'Mexico'}

Query over a field which is deep inside MongoDB collection using array of possible options

I have a list of commentDocument collection in MongoDB where each has the following structure: { "commentName": "test comment", "outputs": { "ex

Access root document map in the $filter aggregation (MongoDb)

I apologize for the vague question description, but I have quite a complex question regarding filtration in MongoDB aggregations. Please, see my data schema to

Slow query using aggregation framework mongodb

I came up with this code to query a list of questions from db question .aggregate([ { $lookup: { from: "answers", localFie

Find in which polygon certain coordinate (latitude, longitude) lies with MongoDB?

Let's say 100 documents (so to say polygons) in a collection named Areas with this structure: { ...otherFields, commonName: "Butwal", area: { type: "