-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueries.txt
57 lines (31 loc) · 1.4 KB
/
queries.txt
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
db.bookmarks.find({"summary": {$regex: ".*tags.*"}})
db.bookmarks.find({$or: [{"summary": {$regex: ".*tags.*"}}, {"contents": {$regex: ".*tags.*"}}]})
> Produces required result as the output
db.bookmarks.aggregate([{$lookup: {from: "comments", localField: "id", foreignField: "bookmarkId", as: "comments"}}])
! NOW?
db.members.updateMany(
{ },
[
{ $set: { status: "Modified", comments: [ "$misc1", "$misc2" ], lastUpdate: "$$NOW" } },
{ $unset: [ "misc1", "misc2" ] }
]
)
db.teachers.find().forEach((doc) => {
db.teachers4.insert(doc)
})
db.bookmarks.find().forEach((bm) => {print(bm)})
db.bookmarks.updateMany({}, {$set: {"comments": []}}, false, true)
db.bookmarks.find({"comments": {$exists: false}})
db.bookmarks.updateMany({"comments": {$exists: false}}, {$set: {"comments": []}}, false, true)
! This worked!
db.comments.find().forEach((comment) => { db.bookmarks.updateOne({id: comment.bookmarkId}, {$push: {"comments": comment}}) })
! todo: run once code is changed!
db.comments.drop()
// Get full bookmark with comments
db.bookmarks.find({"id": "561ae085-9a7f-45a9-8c59-e29944eed86e"})
// Query for bookmarks without comments
db.bookmarks.aggregate([{$project: {comments: 0}}])
// Bookmarks with comments count
db.bookmarks.aggregate([{$addFields: {"comments_count": {$size: "$comments"}}}])
// Remove comments field
db.bookmarks.updateMany({}, { $unset: { comments: "" }})