adding in stuff to make search work but still testing and stuff

This commit is contained in:
talksik
2022-03-18 12:37:39 -04:00
parent 726ab29b64
commit 1ff61bf91d
12 changed files with 225 additions and 64 deletions
+26
View File
@@ -31,6 +31,32 @@ export class UserService {
return null;
}
static async getUsersLikeEmailAndName(searchQuery: string) {
// based on index defined in Mongo atlas
const query = {
$search: {
index: "default",
text: {
query: searchQuery,
path: {
wildcard: "*",
},
},
},
};
// const res = await collections.users?.find(query).toArray();
const res = await collections.users?.aggregate([query]).toArray();
// exists
if (res?.length) {
return res as User[];
}
return null;
}
static async createUserIfNotExists(newUser: User) {
const exists = (await collections.users?.findOne({ email: newUser.email }))
?._id;