Answer the question
In order to leave comments, you need to log in
Sampling from an array with schema in Mongoose?
I have a view schema in Mongoose:
var schema = new Schema({
// ...
views: [new Schema({
userId: String,
expired: Date
})]
});
exports.Order = mongoose.model("Order", schema);
views
is the subschema. I need to select rows from the main schema that EITHER do not contain views with that userId OR do, but views.expired
must expire. Something similar to a system for blocking certain users with a period. How I try to make a selection:Order.find({
$and: [
// other conditions
{ $or: [{"views.userId": { $ne: userId } }, { $and: [
{ "views.userId": userId },
{ "views.expired": { $gte: new Date()}}
]}]}
]
}, function (err, data) {
if (err) console.log(err);
console.log(data);
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question