0

For a collection nameed 'duplicate', we can execute db.duplicate.find( { $where: "this.all_dups.length > 0" } ); but what would be the Python version of this query? I tried using

db.duplicate.find( { "$where": {"$gt":{"all_dups.length"} > 0] }} )

but it is showing me error for obvious reasons.

I also tried

db.duplicate.find( { "all_dups" : { "$size": { "$gt" : 0 }}})

I can do it in Python like:

for a in db.duplicate.find():
    if 'all_dups' in a and len(a['all_dups'])>0:
        print(a)

How can I achieve in PyMongo? I think there $exists, $where, $gt and $size will be used but I don't exactly know how.

1 Answer 1

1

You could try a search that excludes an empty list or a blank list:

db.duplicate.find({"all_dups": {'$nin': [[], None]}})
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.