-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.js
More file actions
33 lines (30 loc) · 1.24 KB
/
search.js
File metadata and controls
33 lines (30 loc) · 1.24 KB
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
const MongoClient = require('mongodb').MongoClient;
const $ = require('jquery');
var mongoURL = "mongodb://zeroth:P455w0rd@ct-cluster-shard-00-00-y9kdv.mongodb.net:27017,ct-cluster-shard-00-01-y9kdv.mongodb.net:27017,ct-cluster-shard-00-02-y9kdv.mongodb.net:27017/test?ssl=true&replicaSet=CT-Cluster-shard-0&authSource=admin";
$('#txtSearch').keyup(()=>{
MongoClient.connect(mongoURL, function(err, db){
console.log('Db connected! from keyup event!');
if(err) throw err;
var search = $('#txtSearch').val();
db.collection('costumers').find({firstname: search}).toArray((err, result)=>{
$('#searchResult').empty();
$('#searchResult').append(result);
console.log(result);
});
db.close();
});
});
$('#btnSearch').click((e)=>{
e.preventDefault();
MongoClient.connect(mongoURL, function(err, db){
console.log('Db connected! from click event!');
if(err) throw err;
var search = $('#txtSearch').val();
db.collection('costumers').find({name: search}).toArray((err, result)=>{
$('#searchResult').empty();
$('#searchResult').append(result[0].name);
console.log(result);
});
db.close();
});
});