mongoose-keywordize icon indicating copy to clipboard operation
mongoose-keywordize copied to clipboard

Support subdocument arrays

Open ragulka opened this issue 12 years ago • 1 comments

It would be great if this plugin would support subdocument arrays. Consider the following:

var pet = new Schema({
    name: String
  , kind: String
});

var child = new Schema({
    name: String
  , pets: [pet]
});

var schema = new Schema({
    name: { first: String, last: String }
  , tags: [String]
  , langs: [String]
  , kids: [child]
});

var opts = {};
opts.fields = ['name.first', 'name.last', 'langs', 'kids.name', 'kids.pets.name', 'kids.pets.kind'];

schema.plugin(keywordize, opts);
var Person = mongoose.model('Person', schema);

var person = new Person({
  name: { first: 'Aaron' },
  kids: [{ name: 'John', pets: [
    { name: 'betty', kind: 'cat' },
    { name: 'beethoven', kind: 'dog' }]
  }]
});

Currently, keywordize simply ignores any arrays of nested documents, but it would make sense to actually take them into account when generating keywords.

ragulka avatar Mar 05 '14 11:03 ragulka

Good idea. I'll accept a pull request that adds support.

On Wednesday, March 5, 2014, ragulka [email protected] wrote:

It would be great if this plugin would support subdocument arrays. Consider the following:

var pet = new Schema({ name: String , kind: String}); var child = new Schema({ name: String , pets: [pet]}); var schema = new Schema({ name: { first: String, last: String } , tags: [String] , langs: [String] , kids: [child]}); var opts = {};opts.fields = ['name.first', 'name.last', 'langs', 'kids.name', 'kids.pets.name', 'kids.pets.kind']; schema.plugin(keywordize, opts);var Person = mongoose.model('Person', schema); var person = new Person({ name: { first: 'Aaron' }, kids: [{ name: 'John', pets: [ { name: 'betty', kind: 'cat' }, { name: 'beethoven', kind: 'dog' }] }]});

Currently, keywordize simply ignores any arrays of nested documents, but it would make sense to actually take them into account when generating keywords.

Reply to this email directly or view it on GitHubhttps://github.com/aheckmann/mongoose-keywordize/issues/5 .

Aaron @aaronheckmann https://twitter.com/#!/aaronheckmann soundcloud.com/ajhecky github.com/aheckmann

aheckmann avatar Mar 05 '14 17:03 aheckmann