Seeking help on filtering arrays in MongoDB where contents are not null or exist but still seeing empty arrays being returned...
const userSchema = new mongoose.Schema({
email: String,
password: String,
googleId: String,
facebookId: String,
secret: Array
});
app.get("/secrets", function(req, res) {
User.find({secret: {$ne: null} }, function(err, secrets) {
if (err) {
console.log(err);
} else {
if (secrets) {
console.log(secrets);
res.render("secrets", {
secrets: secrets
});
};
};
});
});
After researching online, I understand that $ne: null only filters out documents where the secret array doesn't exist. But what to do when it's an empty array? Any tips on resolving this issue for a newbie like me? Your kindness is appreciated! :)