meteor-astronomy
meteor-astronomy copied to clipboard
When querying do not override the "type" property if already defined in selector
In Astronomy, as far as I know every class that inherits from another one creates or uses a type field. This works as expected, but when I try to find all the documents using the parent class and the type field, the query is not applied at all.
For instance:
Meteor.publish('contents', function( query ){
if ( !query ) query = {};
query.userId = this.userId;
query.type = { $in: [ 'foo' ] } // Hard coded to fail
return Content.find( query );
});
The previous publish should not return any document, but it does return all the documents whose parents type is content. The weird part if that it does filter the userId, but not the type field. Any ideas why?
-- I know that I can query the child class. For instance:
// The entity
ImageContent = Content.inherit({
name: 'ImageContent'
});
// The publication
Meteor.publish('contents.images', function( query ){
if ( !query ) query = {};
query.userId = this.userId;
return ImageContent.find( query );
});
But that isn't what I'm looking for.
Hmm that's because Astronomy is overriding the type property in selector. Probably I shouldn't do that if developer already provided the type property. Of course you will lose ability to pass inheritance option to the find method but as you said it does not matter in this case. I think I can implement such an option. When developer overrides the type property than I can assume that he/she knows what he/she is doing.
Ok it's fixed in version 2.4.3
I knew it had to do with the type property. Thank you for fixing this.
I have another question, that perhaps is not exactly related to this one. Is the type property treated as a MongoDB index? It would be nice to be able to use something like this:
let query = { $text: { $search: 'Foo' } };
I tried this with the type, but it seems it was not seeing it as an index. The $text operator is a very powerful way to search strings, but it only iterates over the document's indexes.
Currently index is not created but you can easily create index by yourself. However, text indexes is not much useful for the type property as you're mostly searching for whole phrases and not parts of the type name. For the type property you should use standard index. I will add that one in the next release.