You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem arises when we try to use the addToSet function with a boolean field.
In our use case, we have a boolean field 'is_flag'. When we try to use addToSet to ensure that we only have unique values in this field, the mock library does not support this operation. This is inconsistent with the real MongoDB functionality, which does support addToSet on boolean fields, and this inconsistency is impeding our ability to conduct accurate unit tests.
We kindly request that this issue be addressed, as it is critical for our code to function as expected.
Steps to reproduce the issue:
Create a boolean field in a MongoDB document.
Code query example:
pipeline = [
{"$match": {"my_id": my_id},
{
"$group": {
# We group by 0 to get all the documents in the collection
# and then we use $addToSet to get the unique values
"_id": 0,
"flags": {"$addToSet": "$is_flag"},
}
},
]
flags = await myDocument.aggregate(pipeline).to_list(1)
Attempt to use addToSet function on this boolean field.
Expected Outcome: The addToSet function should work on boolean fields, ensuring that there are only unique values in this field. 'flags': [False]
Actual Outcome: The addToSet function does not support boolean fields, causing unexpected behavior returns: 'flags': [None].
We look forward to your help in resolving this issue. Thank you.
The text was updated successfully, but these errors were encountered:
I think mongomock not support boolean (although mongo does support it):
elif operator == '$addToSet':
value = []
val_it = (val or None for val in values)
# Don't use set in case elt in not hashable (like dicts).
for elt in val_it:
if elt not in value:
value.append(elt)
doc_dict[field] = value
The problem arises when we try to use the addToSet function with a boolean field.
In our use case, we have a boolean field 'is_flag'. When we try to use addToSet to ensure that we only have unique values in this field, the mock library does not support this operation. This is inconsistent with the real MongoDB functionality, which does support addToSet on boolean fields, and this inconsistency is impeding our ability to conduct accurate unit tests.
We kindly request that this issue be addressed, as it is critical for our code to function as expected.
Steps to reproduce the issue:
Create a boolean field in a MongoDB document.
Code query example:
Attempt to use addToSet function on this boolean field.
Expected Outcome: The addToSet function should work on boolean fields, ensuring that there are only unique values in this field. 'flags': [False]
Actual Outcome: The addToSet function does not support boolean fields, causing unexpected behavior returns: 'flags': [None].
We look forward to your help in resolving this issue. Thank you.
The text was updated successfully, but these errors were encountered: