0

In Mongodb Aggregation Framework, you have arithmetic operators like $multiply or $add and so on, I know you can do something similar to { $multiply : [ myField, 0 ] } easily in MongoDb, but how can you do it in Java? I tried new BasicDBObject("$multiply", new BasicDBObject(myField, 0))" in Java, but I got

"errmsg" : "exception: the $multiply operator does not accept an object as an operand". 

So I wonder if you can do the same thing in Java?

Thanks!!

1 Answer 1

2

Note that the value of $multiply operator should be an array not an object. So, in Java the code will be:

BasicDBList args  = new BasicDBList();
args.add(myField);
args.add(0);

new BasicDBObject("$multiply", args)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.