var catProds = mongoose.model('SV_Catgeory_Products');
var prods = mongoose.model('SV_Products');
var obsr=catProds.aggregate([
{
$lookup:
{
from: "prods",
localField: "productId",
foreignField: "productId",
as: "inventory_docs"
}
}
])
console.log(obsr);
Aggregate {
_pipeline: [ { '$lookup': [Object] } ],
_model:
{ [Function: model]
hooks: Kareem { _pres: {}, _posts: {} },
base:
Mongoose {
connections: [Object],
plugins: [],
models: [Object],
modelSchemas: [Object],
options: [Object] },
modelName: 'SV_Catgeory_Products',
model: [Function: model],
db:
NativeConnection {
base: [Object],
collections: [Object],
models: [Object],
config: [Object],
replica: false,
hosts: null,
host: 'localhost',
port: 27017,
user: undefined,
pass: undefined,
name: 'satvik',
options: [Object],
otherDbs: [],
_readyState: 2,
_closeCalled: false,
_hasOpened: false,
_listening: false,
db: [Object],
_events: [Object],
_eventsCount: 1 },
discriminators: undefined,
schema:
Schema {
obj: [Object],
paths: [Object],
subpaths: {},
virtuals: [Object],
singleNestedPaths: {},
nested: {},
inherits: {},
callQueue: [Object],
_indexes: [],
methods: {},
statics: {},
tree: [Object],
_requiredpaths: undefined,
discriminatorMapping: undefined,
_indexedpaths: undefined,
query: {},
childSchemas: [],
s: [Object],
options: [Object],
'$globalPluginsApplied': true },
collection:
NativeCollection {
collection: null,
opts: [Object],
name: 'sv_catgeory_products',
collectionName: 'sv_catgeory_products',
conn: [Object],
queue: [],
buffer: true,
emitter: [Object] },
Query: { [Function] base: [Object] },
'$__insertMany': [Function],
insertMany: [Function] },
options: undefined }
Hi,
I am using mongoose for communication with mongodb. I am using Mongoose aggregation.lookup for joining two tables and i am not able to get the collection of records. Can somebody tell me what is the problem?
It looks like you didn’t provide a callback to the aggregate() call. Without a callback, it will return the Aggregate object instead. To execute the aggregation, you can either:
aggregate() call (see http://mongoosejs.com/docs/api.html#model_Model.aggregate)aggregate().exec() function (see http://mongoosejs.com/docs/api.html#aggregate_Aggregate-exec)Please note that for $lookup, you need to know the collection name as stored by MongoDB. Please see http://mongoosejs.com/docs/guide.html#collection for Mongoose collection name options and default.
If you are still having issues, could you post:
Best regards,
Kevin
Hi
hi do you have one mongoose lookup example source ?
Please take a look at the example in the mongoose documentation: http://mongoosejs.com/docs/api.html#aggregate_Aggregate-lookup
Best regards,
Kevin