-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Slice does not project "select: false" related properties #11940
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Comments
lyaici
changed the title
Slice do not project "select: false" concerned properties
Slice do not project "select: false" related properties
Jun 16, 2022
lyaici
changed the title
Slice do not project "select: false" related properties
Slice does not project "select: false" related properties
Jun 16, 2022
vkarpov15
added
the
needs repro script
Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue
label
Jun 17, 2022
IslandRhythms
added
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
and removed
needs repro script
Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue
labels
Jun 21, 2022
const mongoose = require('mongoose');
const commentSchema = new mongoose.Schema({
comment: String
});
const testSchema = new mongoose.Schema({
name: String,
comments: { type: [commentSchema], select: false}
});
const Test = mongoose.model('Test', testSchema);
async function run() {
await mongoose.connect('mongodb://localhost:27017');
await mongoose.connection.dropDatabase();
await Test.create({
name: 'Test',
comments: [{comment: 'This is a test'}, {comment: 'This should show up'}]
});
const fail = await Test.find().slice('comments', [{limit: 1}, {offset: 0}]);
console.log('fail', fail);
const alsoFail = await Test.find().slice('comments', [{limit: 1}, {offset: 0}]).select('comments');
console.log('alsoFail', alsoFail);
console.log(alsoFail[0].comments)
const works = await Test.find().slice('comments', [{limit: 1}, {offset: 0}]).select('+comments');
console.log('returns everything', works);
}
run(); output:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prerequisites
Mongoose version
6.3.4
Node.js version
16.14.2
MongoDB server version
5.0.6
Description
When using slice on a
select: false
property defined in the schema, the property is not returned, and using select afterwards on this property onlyselect('property')
overwrites the slice (this behaviour is explained on the issue linked below).So there's currently no way of doing that, except adding this property in the select
select('+property')
which does not overwrite the slice. Another solution is basically to removeselect: false
from schema.This is related to this issue I found here.
Steps to Reproduce
Expected Behavior
The text was updated successfully, but these errors were encountered: