These are chat archives for Automattic/mongoose

5th
Nov 2016
yaragallamurali
@yaragallamurali
Nov 05 2016 01:19
The following is my code in App.js. 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?
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);
The output of my code is as below
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 }
Run code snippetCopy snippet to answer
can any body help me in this
yaragallamurali
@yaragallamurali
Nov 05 2016 01:25
as per mongoose docs i have to get the collection of records which i am not able to
yaragallamurali
@yaragallamurali
Nov 05 2016 05:24
any help will be appreciated
Guilherme Rizzo
@guivr
Nov 05 2016 10:43
Hello people! Is there any way to "search"/match incomplete names with .populate()?
Example:
school.get('/:id/users/search/:name', (req, res) => {
  School.findOne({_id: req.params.id})
  .select('users')
  .populate({
    path: 'users',
    match: {
      name: req.params.name //Just works if i have the full name 'Guilherme Rizzo', not 'Gui'
    }
  })