3

Create a ProjectionOperation with Difference with spring mongodb

 3 years ago
source link: https://stackoverflow.com/questions/46786577/create-a-projectionoperation-with-difference-with-spring-mongodb
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Create a ProjectionOperation with Difference with spring mongodb

I have an projection, whitch i have to translate to java and i get not the correct result, like in the mongo db executer with javascript.

{
        $project: {"userId": 1, "followingAndNotFollowingBack": {
            $setDifference: ["$following", "$follower"]}}
}

until now i have in Java the following:

private static final ProjectionOperation PROJECTION_OPERATION = Aggregation.project(UserRelationships.FIELD_USER_ID)
            .and(SetOperators.SetDifference.arrayAsSet(UserRelationships.FIELD_FOLLOWING_USER_IDS)
                    .differenceTo(UserRelationships.FIELD_FOLLOWER_USER_IDS))
            .as(FOLLOWING_AND_NOT_FOLLOWED_BACK);

but i get everytime an null
did anybody see the problem?

thanks a lot


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK