Hi Nilesh
It’s been some time since you posted this question. Have you found a solution in the meantime?
The error message you observe is because you’re trying to set the flag
field twice in a single statement. Having said that, is there a specific reason why you need to use a bit field in your document? Please note that currently MongoDB supports the $bit
operation on either 32-bit or 64-bit integer fields (see $bit). Alternatively, is it possible in your design to enumerate the “flags” into a sub-document or an array instead? For example:
{... info: {a: 0, b: 1, c: 1, d: 1} ...}
or using boolean values:
{... info: {a: false, b: true, c: true, d: true} ...}
Expected:
If exists then and existing flag with 14
Else insert with flag: 14
The update method doesn’t currently support conditionals in its operation. If you need to implement some logic in your update, you may find it easier to implement it in your application code instead.
Best regards,
Kevin
flag
field twice in a single statement It is twice, but once in $setOnInsert, which should never collide with $bit.. In other words flag is once in insert and once in update($bit).