How to group result of lookup aggregate results - javascript

I aggregate users document:
User.aggregate([
{
$match: { _id: req.params.id },
},
{
$lookup: {
from: 'moods',
localField: '_id',
foreignField: 'source.userId',
pipeline: [
{
$lookup: {
from: 'contactrequests',
localField: 'source.userId',
foreignField: 'source.userId',
let: {
// truncate timestamp to start of day
moodsDate: {
$dateTrunc: {
date: '$timestamp',
unit: 'day',
},
},
},
pipeline: [
{
$match: {
$expr: {
$eq: [
'$$moodsDate',
{
// truncate timestamp to start of day
$dateTrunc: {
date: '$timestamp',
unit: 'day',
},
},
],
},
},
},
],
as: 'contactRequests',
},
},
],
as: 'calendar',
},
},
]).exec()
There is final document what I get
{
"_id": "P4SpYVd1KjBaF4SKyVw0E",
"lastName": "Doe",
"login": "User-01",
"name": "John"
"calendar": [
{
"_id": "62a351e33859aaf975c63323",
"source": {
"userId": "P4SpYVd1KjBaF4SKyVw0E",
"deviceId": "Pacjent-141214"
},
"timestamp": "2022-06-07T12:44:13.333Z",
"mood": "good",
"contactRequests": []
},
{
"_id": "62a351f43859aaf975c63327",
"source": {
"userId": "P4SpYVd1KjBaF4SKyVw0E",
"deviceId": "Pacjent-141214"
},
"timestamp": "2022-06-09T12:44:13.333Z",
"mood": "middle",
"contactRequests": [
{
"timestamp": "2022-06-09T12:44:13.333Z",
"source": {
"deviceId": "Pacjent-141214",
"userId": "P4SpYVd1KjBaF4SKyVw0E"
},
"resolve": false,
"_id": "62a351ff3859aaf975c63329",
},
]
}
]
},
This is what I would to get. This is more clean and readable.
{
"_id": "P4SpYVd1KjBaF4SKyVw0E",
"login": "User-01",
"name": "John",
"lastName": "Doe",
"calendar": [
{
"timestamp": "2022-06-11T12:44:13.333Z"
"mood": {
"source": {
"userId": "P4SpYVd1KjBaF4SKyVw0E",
},
"timestamp": "2022-06-11T12:44:13.333Z",
"mood": "bad",
"_id": "62a352b83859aaf975c6332d",
},
"contactRequest": [
{
"timestamp": "2022-06-11T15:25:13.333Z",
"source" : {
"userId":"P4SpYVd1KjBaF4SKyVw0E"
},
"resolve": true,
"_id": "62a351ff3859aaf975c63329"
},
{
"timestamp": "2022-06-11T18:23:13.333Z",
"source" : {
"userId":"P4SpYVd1KjBaF4SKyVw0E"
},
"resolve": false,
"_id": "62a351ff3859aaf975c63329"
},
]
}
}
]
}
To achive that I've used $group parameter, but at some point I have to declare which field should be fetch to result document and I have problem with contatRequest fields.
{
$group: {
_id: {
$dateToString: {
format: '%Y-%m-%d',
date: '$timestamp',
},
},
mood: {
$push: {
_id: '$_id',
source: '$source',
type: '$mood',
timestamp: '$timestamp',
},
},
contactRequest: {
$push: {
_id: '$contactRequest._id',
source: '$contactRequest.source',
resolve: '$contactRequest.resolve',
timestamp: '$contactRequest.timestamp',
},
},
},
},
{
$project: {
_id: 0,
timestamp: '$_id',
mood: 1,
contactRequest: 1,
},
},
Sample database/collections/aggregation pipeline at mongoplayground.net.

Related

MongoDB : - Merge object with same key into one

I am trying to merge an object inside an array with the same date but with a different key name for the status key.
I have 2 collections users and canteens
The query I am trying to get the result but am not able to figure out how to merge the object with the same Date
OUTPUT
User.aggregate([
{ $sort: { workerId: 1 } },
{
$lookup: {
from: "canteens",
localField: "_id",
foreignField: "employeeId",
pipeline: [
{
$match: {
Date: {
$gte: new Date(fromDate),
$lte: new Date(toDate),
},
},
},
{
$project: {
Date: 1,
status: 1,
},
},
],
as: "canteens",
},
},
{
$project: {
_id: 1,
workerId: 1,
workerFirstName: 1,
workerSurname: 1,
workerDepartment: 1,
workerDesignation: 1,
locationName: 1,
canteenData: "$canteens",
},
},
]);
[
{
"_id": "60e6fd3616dd663e84a925e2",
"workerFirstName": "Firstaname",
"workerSurname": "lastname",
"workerId": "1",
"locationName": "location",
"workerDesignation": "designation",
"workerDepartment": "department",
"canteenData": [
{
"_id": "63b285b9e92eee614feb7be1",
"status": "LUNCH",
"Date": "2023-01-02T00:00:00.000Z"
},
{
"_id": "63b2db8db10c24487201e0a2",
"status": "DINNER",
"Date": "2023-01-02T00:00:00.000Z"
},
{
"_id": "63b39b247adbeb50bfbe3503",
"status": "BREAK FAST",
"Date": "2023-01-03T00:00:00.000Z"
},
{
"_id": "63b3d248c076184fb07ff2c4",
"status": "LUNCH",
"Date": "2023-01-03T00:00:00.000Z"
},
{
"_id": "63b42b8ccb57a4cb7af34015",
"status": "DINNER",
"Date": "2023-01-03T00:00:00.000Z"
},
{
"_id": "63b4ef71e038498fe6634506",
"status": "BREAK FAST",
"Date": "2023-01-04T00:00:00.000Z"
}
]
},
{
"_id": "60e6fd3616dd663e84a925e2",
"workerFirstName": "Firstaname1",
"workerSurname": "lastname1",
"workerId": "2",
"locationName": "location",
"workerDesignation": "designation",
"workerDepartment": "department",
"canteenData": [
{
"_id": "63b285b9e92eee614feb7be1",
"status": "LUNCH",
"Date": "2023-01-02T00:00:00.000Z"
},
{
"_id": "63b2db8db10c24487201e0a2",
"status": "DINNER",
"Date": "2023-01-02T00:00:00.000Z"
},
{
"_id": "63b39b247adbeb50bfbe3503",
"status": "BREAK FAST",
"Date": "2023-01-03T00:00:00.000Z"
},
{
"_id": "63b3d248c076184fb07ff2c4",
"status": "LUNCH",
"Date": "2023-01-03T00:00:00.000Z"
},
{
"_id": "63b42b8ccb57a4cb7af34015",
"status": "DINNER",
"Date": "2023-01-03T00:00:00.000Z"
},
{
"_id": "63b4ef71e038498fe6634506",
"status": "BREAK FAST",
"Date": "2023-01-04T00:00:00.000Z"
}
]
}
]
The output I am trying to get
[
{
"_id": "60e6fd3616dd663e84a925e2",
"workerFirstName": "Firstanem",
"workerSurname": "lastname",
"workerId": "1",
"locationName": "location",
"workerDesignation": "designation",
"workerDepartment": "department",
"canteenData": [
{
"_id": "63b285b9e92eee614feb7be1",
"status1": "LUNCH",
"status2": "DINNER",
"Date": "2023-01-02T00:00:00.000Z"
},
{
"_id": "63b39b247adbeb50bfbe3503",
"status1": "BREAK FAST",
"status2": "LUNCH",
"status3": "DINNER",
"Date": "2023-01-03T00:00:00.000Z"
},
{
"_id": "63b4ef71e038498fe6634506",
"status1": "BREAK FAST",
"Date": "2023-01-04T00:00:00.000Z"
}
]
},
{
"_id": "60e6fd3616dd663e84a925e2",
"workerFirstName": "Firstanem1",
"workerSurname": "lastname1",
"workerId": "2",
"locationName": "location",
"workerDesignation": "designation",
"workerDepartment": "department",
"canteenData": [
{
"_id": "63b285b9e92eee614feb7be1",
"status1": "LUNCH",
"status2": "DINNER",
"Date": "2023-01-02T00:00:00.000Z"
},
{
"_id": "63b39b247adbeb50bfbe3503",
"status1": "BREAK FAST",
"status2": "LUNCH",
"status3": "DINNER",
"Date": "2023-01-03T00:00:00.000Z"
},
{
"_id": "63b4ef71e038498fe6634506",
"status1": "BREAK FAST",
"Date": "2023-01-04T00:00:00.000Z"
}
]
}
]
One option is to add 2 steps into your $lookup pipeline aggregation:
{$group: {
_id: "$Date",
_idVal: {$first: "$_id"},
data: {$addToSet: "$status"}
}},
{$replaceRoot: {
newRoot: {
$mergeObjects: [
{_id: "$_idVal", Date: "$_id"},
{$arrayToObject: {
$reduce: {
input: "$data",
initialValue: [],
in: {$concatArrays: [
"$$value",
[{k: {$concat: [
"status",
{$toString: {$add: [{$size: "$$value"}, 1]}}
]},
v: "$$this"}]
]}
}
}}
]
}
}}
See how it works on the playground example
It's not easy to create status1, status2, ... variables dynamically + how do we know BREAK FAST should be status1 and not status2.
Alternative solution: We $group inside correlated subqueries and push all status values into an array
db.users.aggregate([
{
"$lookup": {
"from": "canteens",
"localField": "_id",
"foreignField": "employeeId",
pipeline: [
{
// Put your custom filters here
$match: {}
},
{
$group: {
_id: "$Date",
//pick "first" canteens _id
id: {
$first: "$_id"
},
status: {
$push: "$status"
}
}
},
{
$project: {
_id: "$id",
Date: "$_id",
status: 1
}
},
],
as: "canteenData",
}
}
])
MongoPlayground

Find user is registered to a Event in MongoDb (aggregation)

I tried to find users who are registered for that event.
So I join multiple collections shown below -
Events.aggregate([
{ $match: { category: "group_event" } },
// collection where events are scheduled
{
$lookup: {
from: "group_events",
let: { eventId: "$eventID" },
pipeline: [
{
$match: {
$expr: {
$and: [
{ $eq: ["$_id", "$$eventId"] },
{ $gt: ["$time", new Date()] },
],
},
},
},
// register user collection
{
$lookup: {
from: "register_events",
let: { eventId: "$_id" },
pipeline: [
{ $match: { $expr: { $eq: ["$eventId", "$$eventId"] } } },
],
as: "registerUsers",
},
},
],
as: "events",
},
},
{ $unwind: "$events" },
])
and the output is now comingout -
[
{
"_id": "614d6dfd82cb36be231083c9",
"trainerId": "61488dc36b7ccedbc884d20a",
"category": "group_event",
"eventID": "614d6dfc82cb36be231083c7",
"createdAt": "2021-09-24T06:19:41.268Z",
"updatedAt": "2021-09-24T06:19:41.268Z",
"__v": 0,
"events": {
"_id": "614d6dfc82cb36be231083c7",
"groupName": "group name 4",
"category": "sdfsdf",
"time": "2021-09-27T07:44:58.762Z",
"description": "description",
"day": "sunday",
"platform": "zoom",
"notes": "22",
"skills_to_learn": [
"demo"
],
"status": "pending",
"trainerId": "61488dc36b7ccedbc884d20a",
"meetingLink": "https://us05web.zoom.us/j/81660534858?pwd=cGZaODVjdWJUQWNtN243MlNiVUN0UT09",
"type": "group_event",
**isUserRegisted : true / false,**
"createdAt": "2021-09-24T06:19:41.000Z",
"updatedAt": "2021-09-24T06:19:41.000Z",
"__v": 0,
"registerUsers": [
{
"_id": "614ed6b4b8a545acb8517e85",
"userId": "614d59371d11becb8e23f536",
"eventId": "614d6dfc82cb36be231083c7",
"question": "",
"createdAt": "2021-09-25T07:58:44.939Z",
"updatedAt": "2021-09-25T07:58:44.939Z",
"__v": 0
}
]
}
}
]
which is ok for me bu just wanted to add a key: value, heighlited on obove section
isUserRegisted : true / false
i tried with $addFields but can't came up with any solution. Basically I need to retrieve arrays from registerUsers - collection and on the same time match the userId
I was able to figure out this issue.
simply I need to use $project and $filter to get the data if available and at last use $cond to return true or false
{
$project: {
root: "$$ROOT",
userFound: {
$filter: {
input: "$registerUsers",
as: "ac",
cond: {
$eq: ["$$ac.userId", mongoose.Types.ObjectId(userId)],
},
},
},
},
},
{
$project: {
_id: 0,
document: "$$ROOT",
userFound: {
$cond: {
if: { $isArray: "$userFound" },
then: {
$cond: {
if: {
$gt: [{ $size: "$userFound" }, 0],
},
then: true,
else: false,
},
},
else: false,
},
},
},
},
// merging nested object with parents
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
"$document.root",
{ isUserRegistered: "$userFound" },
],
},
},
},

Aggregate data from nested array

I need help with the aggregate framework.
I have a model (currencies field can contain more than one object):
const schema = new mongoose.Schema({
country: { type: String },
code: { type: String },
region: [{
name: { type: String },
path: { type: Array },
city: [{
name: { type: String },
path: { type: Array },
latitude: { type: String },
longitude: { type: String },
}],
}],
currencies: [{
code: { type: String },
name: { type: String },
symbol: { type: String },
}],
})
And I need to receive all currencies without duplicates.
Received data can view like this:
[
{ code: 'string', name: 'sting', symbol: 'string' },
{ code: 'string', name: 'sting', symbol: 'string' },
...
]
// or like this:
[
currencies: [
{ code: 'string', name: 'sting', symbol: 'string' },
{ code: 'string', name: 'sting', symbol: 'string' },
...
]
]
I try to create a query
Geo.aggregate([
{
$group: {
_id: null,
currencies: { $addToSet: '$currencies' },
},
},
])
but receive this data with duplicates and it has many nested arrays:
[
{
"_id": null,
"currencies": [
[
{
"_id": "5cd9486248989616a411fac5",
"code": "JPY",
"name": "Japanese yen",
"symbol": "¥"
}
],
[
{
"_id": "5cd9491a48989616a411fb47",
"code": "TRY",
"name": "Turkish lira",
"symbol": null
}
],
I try this query:
Geo.aggregate([
{
$addFields: {
code: '$currencies.code',
name: '$currencies.name',
symbol: '$currencies.symbol',
},
},
])
But I receive error "TypeError: item is not iterable".
I need little help )
Db data views like this:
{
"_id": {
"$oid": "5c3334a8871695568817eadf"
},
"country": "Singapore",
"code": "sg",
"region": [
{
"path": [
"Singapore"
],
"_id": {
"$oid": "5c3366c63d92ac6e531e05c0"
},
"city": [],
"name": "Central Singapore Community Development Council"
},
....
],
"__v": 0,
"currencies": [
{
"_id": {
"$oid": "5cd948ec48989616a411fb28"
},
"code": "BND",
"name": "Brunei dollar",
"symbol": "$"
},
{
"_id": {
"$oid": "5cd948ec48989616a411fb27"
},
"code": "SGD",
"name": "Singapore dollar",
"symbol": "$"
}
]
}
In aggregate pipeline first you need to unwind the currencies array and then group them by condition to get desired result.
Geo.aggregate([
{
$unwind: '$currencies'
},
{
$group: {
_id: null,
currencies: { $addToSet: '$currencies' },
},
},
])
For more information you can look into documentation here
db.temp.aggregate([
{$project : {currencies : 1}},
{$unwind: "$currencies"},
{
$addFields: {
currencyHash: {
$concat : ['$currencies.code', "--", "$currencies.name", "--", "$currencies.symbol"]
}
}
},
{
$group: {
_id: "$currencyHash",
currency : {
$first : "$currencies"
}
}
},
{
$project: {
code : "$currency.code",
name : "$currency.name",
symbol : "$currency.symbol"
}
},
{
$project: {
_id : 0,
currency : 0
}
}
]).pretty()

How to find average in mongoose aggregation

I am aggregating data from 3 collections -
Users -
[
{
"_id": "5bc425bb3e99c8269ce51faa",
"fname": "Akash",
"salary": 25000,
"age": 23,
"__v": 0
},
{
"_id": "5bc425e23e99c8269ce51fab",
"fname": "Aditya",
"salary": 20000,
"age": 28,
"__v": 0
}
]
Balance -
[
{
"_id": "5bc4349adcc885e047054466",
"fname": "Akash",
"balance": 4000
},
{
"_id": "5bc434ffdcc885e0470544c2",
"fname": "Aditya",
"balance": 8000
}
]
dept collection -
[
{
"_id": "5bc46167b365918881aa3bbf",
"fname": "Akash",
"dept": "IT"
},
{
"_id": "5bc4620fb365918881aa3c1b",
"fname": "Apurva",
"dept": "Chemical"
}
]
I want to aggregriated result as -
[
{
"_id": {
"fname": "Aditya",
"balance": 8000,
"dept": "Medical",
"salary": 20000
},
"avg": 20000
},
{
"_id": {
"fname": "Apurva",
"balance": 1000,
"dept": "Chemical",
"salary": 22000
},
"avg": 22000
}
]
My query -
User.aggregate([
{
$lookup: {
from: "balance",
localField: "fname",
foreignField: "fname",
as: "result"
}
},
{
$unwind: "$result"
},
{
$lookup: {
from: "dept",
localField: "fname",
foreignField: "fname",
as: "deptresult"
}
},
{
$unwind: "$deptresult"
},
{ $sort: { salary: -1 } },
// { $limit: 1 },
{
$project: {
fname: 1,
salary: 1,
"result.balance": 1,
"deptresult.dept": 1,
avg: { $avg: "$salary" }
}
}
It shows remaining result but it does now display calculated average.
Instead of average , it simply prints salary . Please someone guide me on this.
I am using mongoose ORM.Rest of the code is running fine.
You can use below aggregation
User.aggregate([
{ "$facet": {
"projection": [
{ "$lookup": {
"from": "balance",
"localField": "fname",
"foreignField": "fname",
"as": "result"
}},
{ "$lookup": {
"from": "dept",
"localField": "fname",
"foreignField": "fname",
"as": "deptresult"
}},
{ "$unwind": "$deptresult" },
{ "$unwind": "$result" },
{ "$sort": { salary: -1 } },
{ "$project": {
"fname": 1,
"salary": 1,
"result.balance": 1,
"deptresult.dept": 1
}}
],
"averageSalary": [
{ "$group": {
"_id": null,
"avg": { "$avg": "$salary" }
}}
]
}}
])

Sequelize where condition for multiple tables not working

While building Sequelize query unable to filter data from two tables with two different where conditions. Here I am adding some code...
Models:
//Task model
module.exports = function(sequelize, DataTypes) {
var Task = sequelize.define("Task", {
type: DataTypes.STRING(100),
start : DataTypes.DATE,
finish : DataTypes.DATE,
status : DataTypes.STRING(1),
}, {
classMethods: {
associate: function(models) {
Task.belongsTo(models.User, {
onDelete: "CASCADE",
foreignKey: {
allowNull: true
}
});
Task.hasOne(models.Evaluation);
Task.hasMany(models.Clarification);
}
}
});
return Task;
};
//Evaluation model
module.exports = function(sequelize, DataTypes) {
var Evaluation = sequelize.define("Evaluation", {
agent_id : DataTypes.INTEGER,
agent_name: DataTypes.STRING(100),
status: DataTypes.STRING(100),
}, {
classMethods: {
associate: function(models) {
Evaluation.belongsTo(models.Task, {
onDelete: "CASCADE",
foreignKey: {
allowNull: false
}
});
Evaluation.hasMany(models.Clarification);
}
}
});
return Evaluation;
};
//Clarification model
module.exports = function(sequelize, DataTypes) {
var Clarification = sequelize.define("Clarification", {
result : DataTypes.TEXT,
status : DataTypes.STRING(100),
comment : DataTypes.TEXT
}, {
classMethods: {
associate: function(models) {
Clarification.belongsTo(models.Task, {
onDelete: "CASCADE",
foreignKey: {
allowNull: false
}
});
Clarification.belongsTo(models.Evaluation, {
onDelete: "CASCADE",
foreignKey: {
allowNull: false
}
});
}
}
});
return Clarification;
};
I just added required code not exactly same.
Actually Using:
var filterobj = {
where: {
"UserId": { $ne: "NULL" }
},
include: [{
model: models.Evaluation,
attributes: ["id", "status","agent_name"],
where: {
"status": { $ne: "created" }
},
include: [{
model: models.EvalForm,
attributes: ["id", "name","LobId"],
include: [{
model: models.Lob,
attributes: ["id", "ClientId"]
},
{
model: models.FormDetails,
attributes: ["version", "status"]
}
]
}, {
model: models.Clarification,
attributes: ["id", "status"]
}],
required: true
},{
model: models.User,
attributes: ["name"]
}]
};
models.Task.findAll(filterobj).then(function (tasklist) {
// Doing some stuff for specific format
return res.send(tasklist);
}).catch(function (err) {
return res.send({ "error": { "code": 5000, "message": err.message } });
});
Response:
[
{
"id": 760,
"type": "clarification",
"start": "2017-07-12T14:30:52.000Z",
"finish": "2017-07-13T05:41:56.000Z",
"status": "A",
"UserId": 854,
"Evaluation": {
"id": 760,
"status": "completed",
"agent_name": "TestAgent1",
"EvalForm": {
"id": 5000008,
"name": "MobiPostpaid1",
"LobId": 26,
"Lob": {
"id": 26,
"ClientId": 1
},
"FormDetails": [
{
"version": 1,
"status": "A"
}
]
},
"Clarifications": [
{
"id": 70,
"status": "raised"
},
{
"id": 71,
"status": "esclate"
}
]
},
"User": {
"name": "pooja.s"
}
},
{
"id": 761,
"type": "clarification",
"start": "2017-07-12T14:30:52.000Z",
"finish": "2017-07-12T14:35:30.000Z",
"status": "A",
"UserId": 854,
"Evaluation": {
"id": 761,
"status": "assigned",
"agent_name": "TestAgent1",
"EvalForm": {
"id": 5000008,
"name": "MobiPostpaid1",
"LobId": 26,
"Lob": {
"id": 26,
"ClientId": 1
},
"FormDetails": [
{
"version": 1,
"status": "A"
}
]
},
"Clarifications": []
},
"User": {
"name": "pooja.s"
}
}
]
Expected Code(Not working)
var filterobj = {
where: {
"UserId": { $ne: "NULL" }
},
include: [{
model: models.Evaluation,
where: {
"status": { $in: ["assigned","completed"] }
},
attributes: ["id", "status","agent_name"],
include: [{
model: models.EvalForm,
attributes: ["id", "name","LobId"],
include: [{
model: models.Lob,
attributes: ["id", "ClientId"]
},
{
model: models.FormDetails,
attributes: ["version", "status"]
}
]
}, {
model: models.Clarification,
attributes: ["id", "status"]
}],
required: true
},{
model: models.User,
attributes: ["name"]
}, {
model: models.Clarification,
where: {
"status": { $in: ["raised"] }
}
attributes: ["id", "status"]
}]
};
models.Task.findAll(filterobj).then(function (tasklist) {
// Doing some stuff for specific format
return res.send(tasklist);
}).catch(function (err) {
return res.send({ "error": { "code": 5000, "message": err.message } });
});
Expected Response:
[
{
"id": 760,
"type": "clarification",
"start": "2017-07-12T14:30:52.000Z",
"finish": "2017-07-13T05:41:56.000Z",
"status": "A",
"UserId": 854,
"Evaluation": {
"id": 760,
"status": "completed",
"agent_name": "TestAgent1",
"EvalForm": {
"id": 5000008,
"name": "MobiPostpaid1",
"LobId": 26,
"Lob": {
"id": 26,
"ClientId": 1
},
"FormDetails": [
{
"version": 1,
"status": "A"
}
]
},
"Clarifications": [
{
"id": 70,
"status": "raised"
},
{
"id": 71,
"status": "esclate"
}
]
},
"User": {
"name": "pooja.s"
},
"Clarifications": [
{
"id": 70,
"status": "raised"
}
]
},
{
"id": 761,
"type": "clarification",
"start": "2017-07-12T14:30:52.000Z",
"finish": "2017-07-12T14:35:30.000Z",
"status": "A",
"UserId": 854,
"Evaluation": {
"id": 761,
"status": "assigned",
"agent_name": "TestAgent1",
"EvalForm": {
"id": 5000008,
"name": "MobiPostpaid1",
"LobId": 26,
"Lob": {
"id": 26,
"ClientId": 1
},
"FormDetails": [
{
"version": 1,
"status": "A"
}
]
},
"Clarifications": []
},
"User": {
"name": "pooja.s"
},
"Clarifications": []
}
]
I can include Clarification table inside Task and Evaluation tables I have that association. The problem with where condition. It is pulling all the records. I am expecting data from Clarification table with status raised. And from Evaluation table status with assigned and completed. Some where I saw code using OR operator.
A.findAll({
where: {
$or: [
{'$B.userId$' : 100},
{'$C.userId$' : 100}
]
},
include: [{
model: B,
required: false
}, {
model: C,
required: false
}]
});
But this is not working for me.

Categories

Resources