-
Notifications
You must be signed in to change notification settings - Fork 0
/
userDao.js
63 lines (53 loc) · 1.36 KB
/
userDao.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var mongoose = require("mongoose");
console.log("hello world");
var userSchema = new mongoose.Schema({
email: { type: String, unique: true },
propertyIds: [String],
role: String,
propertyNames: [String],
});
const User = mongoose.model("Users", userSchema);
/*
const user1 = new users({
email: "[email protected]",
propertyId: ["111"],
});
*/
function saveUser(email, propertyIds, role) {
return User.updateOne(
{ email: email },
{ propertyIds: propertyIds },
{ role: role },
{ propertyNames: propertyNames },
{ upsert: true }
).then((value) => {
console.log("finished " + JSON.stringify(value));
return value;
});
}
function findUser(email) {
return User.findOne({ email: email }).then((value) => {
console.log("findUser() Repsonse " + JSON.stringify(value));
return value;
});
}
function findAll() {
return User.find({}).then((value) => {
console.log("findAll() response " + JSON.stringify(value));
return value;
});
}
/*
users.updateOne(
{ email: "[email protected]" },
{ propertyId: ["111"] },
{ upsert: true }
);
*/
//console.log(`user1 is ${User}`);
//user1.save();
//module.exports = mongoose.model("User", userSchema);
console.log("all done");
// console.log(findUser("[email protected]"));
// saveUser("[email protected]", ["123", "234"]);
module.exports = { saveUser, findUser, findAll };