Mongoid "exists" does not work as expected
Hi i am trying to execute a query and giving me strange results. I am trying to get a list of objects where the field does not exist with a where clause added.
Take the first step where:
ContentMirror.where(source: 'some_source').count
This query returns 9984 records.
some_source
have a field call vid_emded_obj
that I know nil
For example:
ContentMirror.find('50fff286781200986e000ae3')
=> #<ContentMirror _id: 50fff286781200986e000ae3, _type: nil, created_at: 2012-12-15 13:12:22 UTC, updated_at: 2013-01-29 12:10:23 UTC, deleted_at: nil, title: "Introduction to Polynomials", vid_emded_obj: nil, media_type: "video", source: "some_source", thumbnail_url: nil, md5: "459173975a7fb145b3ca8b99e1c2ae78">
So what I was expecting is that if this number 1 will return, if I do this:
ContentMirror.where(source: 'some_source').exists(vid_emded_obj: false).count
=> 0
I can't, why ...
source to share
I make sure there is a check if the property is present at all and will return true if the value of that property is empty. I'll just hunt for a document to confirm :)
EDIT:
So there is no mention of the existence in the document (...). Only exists? a method that can be applied according to criteria.
I think you should (pseudocode, I haven't tried it)
ContentMirror.count(vid_embed_obj:nil, source: 'some_source')
or
ContentMirror.where(vid_embed_obj:nil, source: 'some_source').count
or again
ContentMirror.excludes(vid_embed_obj:nil).where(source: 'some_source').count
source to share