Nodejs Mongoose Find with values concatenate

This is my first post and need to know how i resolved my problem

I have this code

var searchParams = '{}';
if(typeof nt !== 'undefined') {searchParams = {ticket: {$regex: nt}};}
if(typeof tp !== 'undefined') {searchParams = searchParams + {typet:  {$regex: tp}};}
if(typeof st !== 'undefined') {searchParams = searchParams + {status: {$regex: st}};}

But when I try to put "SearchParams" into my find is not working This is my code in my Find

    db.iModel.find(
        searchParams,
{status:1,datestart:1,typet:1},
        {skip:start,limit:limit}).sort(sortParams).execFind(function (err, IncidentSchema) {

I think may problem is with "searchParams + {typet: {$regex: tp}}" this is not the way to working. this is becouse i try only one parameter is working!!! but wend try more parameter is not working

with console log with one parameter is simple string but with more parameter return this [object Object][object Object]

sorry my english I am spanish

Thanks

The queries to MongoDB are represented as objects and not strings. So you don't "concatenate", but rather "build" the object as you would in native code:

var searchParams = {};
if(typeof nt !== 'undefined') { searchParams["ticket"] = { $regex: nt } }
if(typeof tp !== 'undefined') { searchParams["typet"] = { $regex: tp } }
if(typeof st !== 'undefined') { searchParams["status"] = { $regex: st } }

console.log( JSON.stringify( searchParams, undefined, 2 ) );

Just logging that out so you can see what the resulting query object looks like.

Also note that MongoDB query arguments are by default an "and" operation, so if your actually want an $or condition where either of those conditions can be true then you build that way by pushing to the array:

var searchParams = { "$or": [] };
if(typeof nt !== 'undefined') { seachParams["$or"].push({ "ticket": { $regex: nt }}); }
if(typeof tp !== 'undefined') { searchParams["$or"].push({ "typet": { $regex: tp }}); }
if(typeof st !== 'undefined') { searchParams["$or"].push({ "status": { $regex: st }}); }

console.log( JSON.stringify( searchParams, undefined, 2 ) );