using this schema
const UserSchema = new mongoose.Schema({
username: String,
fName: String,
lName: String,
title: String,
hash: String,
salt: String,
admin: Boolean,
chats: [{ userid: String, messages: [{ user: String, message: String }] }],
});
what is the correct way to find a "_id" along with a specific "userid" using Model.updateOne()?
User.updateOne(
{ _id: data.receiver, chats: { userid: data.sender } },
{ $push: { chats: mes } },
(err, result) => {
if (!err) {
console.log(result);
} else {
console.log(err);
}
}
this ^^^^ doesnt work but this
User.updateOne(
{ _id: data.receiver },
{ $push: { chats: mes } },
(err, result) => {
if (!err) {
console.log(result);
} else {
console.log(err);
}
finds the correct user