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
Bug in Update $set in a Map property #9298
Comments
Which version of Mongoose are you using? On Mongoose v5.9.26, the below script succeeds. 'use strict';
const mongoose = require('mongoose');
mongoose.set('debug', true);
mongoose.set('useFindAndModify', false);
const { Schema } = mongoose;
run().catch(err => console.log(err));
async function run() {
await mongoose.connect('mongodb://localhost:27017/test', {
useNewUrlParser: true,
useUnifiedTopology: true
});
await mongoose.connection.dropDatabase();
const CountrySchema = new mongoose.Schema({
cities: {
type: Map,
of: {
population: {type: Number}
}
}
});
const Country = mongoose.model('Country', CountrySchema);
await Country.updateOne({}, { $set: { "cities.newyork.population": 10000 } }).exec()
console.log('Done');
} |
Sorry for the late delay, I was in vacations, ``it("should work with mongoose", async () => {
|
Given a schema:
When
Country.updateOne({_id:""}, {$set: "cities.newyork.population": 10000} ).exec()
throws Mongoose maps only support string keys, got undefined
Bypassing the mongoose works:
Country.collection.update({_id:""}, {$set: "cities.newyork.population": 10000} )
But it is missing schema validation.
By changing the mongoose/lib/schema/map.js function cast = (val, doc, init) => val it's working...$__schemaType.path ends with ".$ *").
But I am not sure when this should be done in order to create a pull request(maybe when
P.S I can create a pull request with a failing test in order for anyone to investigate it more.
The text was updated successfully, but these errors were encountered: