i have one collection name CategoryCollection and Other is SubcategoryCollection and i want data merging this two collection and i am using mongoose schema for collection
var mongoose = require('mongoose');
var Category= mongoose.Schema({
_id: {
type: string,
default: 0
},
oldinsta: {
type: String,
},
var category= mongoose.model('Cat', Category)
module.exports = category;
and other collection schema is as below
var SubCat= mongoose.Schema({
_id:
{ type: String },
cat_id :{
{type : string}
}
var subcat= mongoose.model('subCategory', SubCat)
module.exports= subcat;
then how to get data betwween this two collection i am new in node js so please help me
i am try like this as below
category.aggregate([
{
$unwind: "$_id"
},
{
$lookup:
{
from: "SubCat",
localField: "_id",
foreignField: "cat_id",
as: "embeddedData"
}
}
], function (err, data) {
console.log(data);
res.send(data);
})