MongoDB Aggregate; Projecting min and max documents

let pipeline = [
        $group: {
            _id: "$user_id",
            minTime: { $min: "$time" },
            maxTime: { $max: "$time" }
        $project: {
            // Looking to take the most recent document, and the
            // oldest document for a user and subtract their "weight"
            // attribute

I am struggling with a MongoDB aggregate problem. I am currently looking to take the oldest document, matching "minTime" and the newest document with time matching "maxTime", and subtracting their "weight" attribute to basically get a net change for the user. How would I go about projecting this in the pipeline?

Read more here:

Content Attribution

This content was originally published by Nicholas Dullam at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: