javascript - Search 2 text fields as 1 field -
i'm search users name , i've properties: firstname , lastname . if had property fullname trivial don't have it. i want search "peter robert" , need combine theses 2 fields 1 before searching. how do it? sounds want "text search" . text indexes can span on multiple fields terms entered searched indexed fields: db.collection.ensureindex({ "firstname": "text", "lastname": "text" }) db.collection.find({ "$text": { "$search": "peter robert" } }) that 1 way handle this. return other matches exact matches have highest score can rank them. alternately, if know getting string "peter robert" in order can "split" , tokenize input: var input = "peter robert"; var parts = input.split(/ /); // splits on space db.collection.find({ "firstname": parts[0], "lastname" parts[1] ]) which pretty basic. or apply $reg...