Skip to content

Commit

Permalink
test(document): repro #6754
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jul 27, 2018
1 parent 7965494 commit 28621a5
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/docs/transactions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,34 @@ describe('transactions', function() {
session.commitTransaction();
});
});

it('populate (gh-6754)', function() {
const Author = db.model('Author', new Schema({ name: String }), 'Author');
const Article = db.model('Article', new Schema({
author: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Author'
}
}), 'Article');

let session = null;
return db.createCollection('Author').
then(() => db.createCollection('Article')).
then(() => db.startSession()).
then(_session => {
session = _session;
session.startTransaction();
return Author.create([{ name: 'Val' }], { session: session });
}).
then(authors => Article.create([{ author: authors[0]._id }], { session: session })).
then(articles => Article.findById(articles[0]._id).session(session)).
then(article => {
assert.ok(article.$session());
return article.populate('author').execPopulate();
}).
then(article => {
assert.equal(article.author.name, 'Val');
session.commitTransaction();
});
});
});

0 comments on commit 28621a5

Please sign in to comment.