Allow populating paths with spaces
Author: vkarpov15Created Oct 16, 2023Updated Sep 15, 2026
Labelsdiscussionbackwards-breaking
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the issue has not already been raised
Issue
The following test fails, there's no way to populate the 'original author' path that I can see:
it('allows populating path with space in name (gh-13951)', async function() {
const BlogPost = db.model('BlogPost', new Schema({
title: String,
'original author': { type: ObjectId, ref: 'User' },
author: { type: ObjectId, ref: 'User' }
}));
const User = db.model('User', new Schema({ name: String }));
const fans = await User.create([{ name: 'Fan 1' }]);
const posts = [
{ title: 'Test 1', author: fans[0]._id, 'original author': fans[0]._id }
];
await BlogPost.create(posts);
const blogPost = await BlogPost.
findOne({ title: 'Test 1' }).
populate({ path: 'original author' });
assert.equal(blogPost['original author'].name, 'Fan 1');
assert.equal(blogPost.title, 'Test 1');
});Worth finding a way to support this behavior without breaking existing logic that relies on whitespace to separate multiple paths.
Source: Automattic/mongoose