Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getters are double called when using get() into a document array #6779

Closed
vkarpov15 opened this issue Jul 28, 2018 · 0 comments
Closed

Getters are double called when using get() into a document array #6779

vkarpov15 opened this issue Jul 28, 2018 · 0 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@vkarpov15
Copy link
Collaborator

Popped up when investigating #6637

const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/gh6637', { useNewUrlParser: true });
const conn = mongoose.connection;
const Schema = mongoose.Schema;

mongoose.set('debug', true);

const schema = new Schema({
  nested: {
    arr: [{ key: String }]
  }
});

schema.path('nested.arr.0.key').get(v => 'foobar' + v);

const Test = mongoose.model('test', schema);

const test = new Test;

test.nested.arr.push({ key: 'value' });
test.nested.arr.push({ key: 'value2' });

async function run() {
  await conn.dropDatabase();
  await test.save();
  let doc = await Test.findOne();
  console.log(doc.get('nested.arr.0.key')); // "foobarfoobarvalue"
}

run();
@vkarpov15 vkarpov15 added this to the 5.2.6 milestone Jul 28, 2018
@vkarpov15 vkarpov15 added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Jul 28, 2018
vkarpov15 added a commit that referenced this issue Jul 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

1 participant