These are chat archives for Automattic/mongoose

18th
Jul 2017
Karthi
@Karthi-SRV
Jul 18 2017 08:07

hi, i like to made join query in aggregate
how can we do it
eg
4 table
Sector, -> { id and name }
Client, { id, client name }
Chatbot { id, client id, Sector Id and name }
Conversation - { chatbot id }

Desired output
Sector Name, Client Name, No of Bot, Conversation Count
Test, Test client, 2 , 40(total conversation in 2 bots)
Test 2, Test Client , 1, 20

How can we do using lookup

Paul "Joey" Clark
@joeytwiddle
Jul 18 2017 09:21
@Karthi-SRV Mongo doesn’t support joins. But you can populate.
You will need a field to contain the _id of the document you want to pull.
Shaad Khan
@shaad-khan
Jul 18 2017 11:09
@shaad-khan
hi need to query data from dataTable object based on matching date field below is the mongodb object:
{
"_id" : ObjectId("596dc649020aa118db8145f7"),
"dataTable" : [
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "Quick Pay",
"Opening" : "0",
"Received" : "2,210",
"Processed" : "2,210",
"Closing" : "0",
"BacklogDays" : "0",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "Carrier",
"Opening" : "68,180",
"Received" : "23,026",
"Processed" : "23,026",
"Closing" : "68,180",
"BacklogDays" : "2.961",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "LTL",
"Opening" : "4,023",
"Received" : "0",
"Processed" : "0",
"Closing" : "4,023",
"BacklogDays" : "0",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "Paper",
"Opening" : "4,760",
"Received" : "12,216",
"Processed" : "12,216",
"Closing" : "4,760",
"BacklogDays" : "0.39",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "Specials",
"Opening" : "569",
"Received" : "1,433",
"Processed" : "1,433",
"Closing" : "569",
"BacklogDays" : "0.397",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "Rails",
"Opening" : "0",
"Received" : "195",
"Processed" : "195",
"Closing" : "0",
"BacklogDays" : "0",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "UPS",
"Opening" : "0",
"Received" : "2,074",
"Processed" : "2,074",
"Closing" : "0",
"BacklogDays" : "0",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "DDNA",
"Opening" : "0",
"Received" : "0",
"Processed" : "0",
"Closing" : "0",
"BacklogDays" : "0",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "Accounting Incidents",
"Opening" : "0",
"Received" : "0",
"Processed" : "0",
"Closing" : "0",
"BacklogDays" : "0",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "Billing Activities",
"Opening" : "0",
"Received" : "0",
"Processed" : "0",
"Closing" : "0",
"BacklogDays" : "0",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "Aging items",
"Opening" : "0",
"Received" : "0",
"Processed" : "0",
"Closing" : "0",
"BacklogDays" : "0",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "Com Checks",
"Opening" : "0",
"Received" : "563",
"Processed" : "563",
"Closing" : "0",
"BacklogDays" : "0",
"VoucherCount" : "5,683"
}
],
"VoucherCount" : null
}
please help as i am new to mongodb
Below is the mongodb object
{
"_id" : ObjectId("596dc649020aa118db8145f7"),
"dataTable" : [
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "Quick Pay",
"Opening" : "0",
"Received" : "2,210",
"Processed" : "2,210",
"Closing" : "0",
"BacklogDays" : "0",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "Carrier",
"Opening" : "68,180",
"Received" : "23,026",
"Processed" : "23,026",
"Closing" : "68,180",
"BacklogDays" : "2.961",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "LTL",
"Opening" : "4,023",
"Received" : "0",
"Processed" : "0",
"Closing" : "4,023",
"BacklogDays" : "0",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "Paper",
"Opening" : "4,760",
"Received" : "12,216",
"Processed" : "12,216",
"Closing" : "4,760",
"BacklogDays" : "0.39",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "Specials",
"Opening" : "569",
"Received" : "1,433",
"Processed" : "1,433",
"Closing" : "569",
"BacklogDays" : "0.397",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "Rails",
"Opening" : "0",
"Received" : "195",
"Processed" : "195",
"Closing" : "0",
"BacklogDays" : "0",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "UPS",
"Opening" : "0",
"Received" : "2,074",
"Processed" : "2,074",
"Closing" : "0",
"BacklogDays" : "0",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "DDNA",
"Opening" : "0",
"Received" : "0",
"Processed" : "0",
"Closing" : "0",
"BacklogDays" : "0",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "Accounting Incidents",
"Opening" : "0",
"Received" : "0",
"Processed" : "0",
"Closing" : "0",
"BacklogDays" : "0",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "Billing Activities",
"Opening" : "0",
"Received" : "0",
"Processed" : "0",
"Closing" : "0",
"BacklogDays" : "0",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "Aging items",
"Opening" : "0",
"Received" : "0",
"Processed" : "0",
"Closing" : "0",
"BacklogDays" : "0",
"VoucherCount" : "5,683"
},
{
"Date" : "2/13/2017 12:00:00 AM",
"Description" : "Com Checks",
"Opening" : "0",
"Received" : "563",
"Processed" : "563",
"Closing" : "0",
"BacklogDays" : "0",
"VoucherCount" : "5,683"
}
],
"VoucherCount" : null
}
matrixbirds
@Matrixbirds
Jul 18 2017 12:09
@shaad-khan try this
mongoose.model(‘modelName’).aggregate([
{‘$unwind’: ‘$dataTable'},
{'$match’: { ‘Date’: "2/13/2017 12:00:00 AM" } },
{'$group': { _id: null, item: { "$first":  “$dateTable” } } }
]);
Shaad Khan
@shaad-khan
Jul 18 2017 12:39
image.png
@Matrixbirds
matrixbirds
@Matrixbirds
Jul 18 2017 16:23
which version u used?
@shaad-khan mongodb version
matrixbirds
@Matrixbirds
Jul 18 2017 16:35
‘$unwind’ probably use mongodb version >= 3.0
Parth Shah
@parths3an
Jul 18 2017 16:36
Hi everyone, I have a quick question. Do you know if there is a way we can use a typescript class as type in mongoose schema?
matrixbirds
@Matrixbirds
Jul 18 2017 16:41
@parths3an use typescript implement http://mongoosejs.com/docs/customschematypes.html ?
Parth Shah
@parths3an
Jul 18 2017 16:43
thank you @Matrixbirds
nacq
@nacq
Jul 18 2017 23:49
Anyone with experience on geo spatial queries?
danillobarbosa
@danillobarbosa
Jul 18 2017 23:53
Hello
I can search for referenced documents using the query like this:model.find ('parent.path': / search / i).exec()