moon
moon

Reputation: 165

How can I build this mongodb query into java code

{
    $group : {...some query operation}, 
    $project : {
        _id:"$_id",
        day_work : { // <-- I can't express this code in Java
            timestamp:"$timestamp",
            view : "$view",
            pay : "$pay"
        }
    }
}

when sample data like this

{
    ... //some field and value,
    timestamp:1411214521,
    view : 3,
    pay : 105
}

If above query does work, I expect this

{
    ... //some field and value,
    day_work : {
            "timestmp":1411214521,
            view : 3,
            pay : 105
    }
}

I try like this

Aggregation.project("_id").andInclude("timestamp","view","pay") // <-- can't merge into day_work

Thanks for your help

Upvotes: 0

Views: 54

Answers (1)

moon
moon

Reputation: 165

I found answer

Aggregation.project() .and("day_work").nested("timestamp","timestamp").and("view","view")...etc

Upvotes: 1

Related Questions