-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatlassearch.js
49 lines (44 loc) · 1.28 KB
/
atlassearch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const { MongoClient } = require("mongodb");
// connect to your Atlas cluster
const uri =
process.env.DB_URL;
const client = new MongoClient(uri);
let docs = [];
async function run() {
try {
await client.connect();
// set namespace
const database = client.db("test");
const coll = database.collection("recipes");
// define pipeline
const agg = [
// [
// {
// '$search': {
// 'index': 'default',
// 'text': {
// 'query': 'lemon',
// 'path': {
// 'wildcard': '*'
// }
// }
// }
// }
// ],
{$search: {text: {query: "lemon", path: "title"}}},
{$limit: 20},
{$project: {_id: 1,title: 1, description: 1, ingredients: 1, method: 1, cook: 1 }}
];
// run pipeline
const result = await coll.aggregate(agg);
// print results
await result.forEach((doc) => {
console.log(doc);
// docs.push(doc);
});
} finally {
// module.exports = docs;
await client.close();
}
}
run().catch(console.dir);