-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Automatically translateAliases()
for queries and updates
#8678
Comments
Mongoose currently doesn't support querying/updating with aliases. Meanwhile, you can use 'use strict';
const mongoose = require('./');
const { Schema } = mongoose;
const assert = require('assert');
mongoose.connect('mongodb://localhost:27017/test', { useNewUrlParser: true, useUnifiedTopology: true });
const userSchema = new Schema({
name: { type: String, alias: 'nameAlias' }
});
const User = mongoose.model('User', userSchema);
async function run() {
await User.deleteMany();
const user = await User.create({ nameAlias: 'Hafez' });
const filter = User.translateAliases({ nameAlias: 'Hafez' });
const changes = User.translateAliases({ nameAlias: 'new name' });
await User.updateOne(filter, changes);
const updatedUser = await User.findOne({ _id: user._id });
assert.equals(updatedUser.nameAlias, 'new name');
}
run().catch(console.error); |
translateAliases()
for queries and updates
Waiting for this feature. It will be really useful. |
Yeah, waiting too |
Please, this is such an easy fix and would be so helpful... |
The team's resources are currently focused on other issues, PRs implementing this functionality are welcome. |
why does the update work for lower-level aliases and not for the top-level fields? eg: const moduleSchema = mongoose.Schema(
{
mt: { type: Number, required: true, alias: "type" },
mp: { type: [Number], required: true, alias: "permissions" },
}
)
const roleSchema = mongoose.Schema(
{
n: { type: String, required: true, alias: "name" },
m: { type: [moduleSchema], required: true, alias: "modules" },
}
) now when i call
and fails to update when if pass data as
|
I also noticed |
I am not able to run an update query
Debug log
Mongoose: Products.updateOne({ _id: ObjectId("5e6e2c2ea1e74d2362c593e3") }, { '$setOnInsert': { createdAt: new Date("Tue, 17 Mar 2020 15:13:57 GMT") }, '$set': { updatedAt: new Date("Tue, 17 Mar 2020 15:13:57 GMT") }}, {})
The text was updated successfully, but these errors were encountered: