Skip to content

Commit b508f24

Browse files
committed
basic mongo js api
1 parent 432f841 commit b508f24

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Practice/Mongo/users.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use practice;
2+
3+
db.users.insert({ name: 'Adam', username: 'adam', password: 'adam123' });
4+
db.users.updateOne({ username: 'adam' }, { $set: { roles: ['student', 'faculty'] } })
5+
6+
db.users.insertOne({
7+
name: 'ben',
8+
username: 'ben',
9+
password: 'ben123'
10+
})
11+
db.users.updateOne({ name: 'ben' }, { $set: { roles: ['faculty'] } });
12+
13+
db.users.aggregate([{ $unwind: '$roles' }])
14+
db.users.aggregate([{ $unwind: '$roles' }, { $group: { _id: '$roles', total: { $count: {} } } }])
15+
16+
db.users.find();
17+
db.users.count;
18+
19+
db.users.drop();

0 commit comments

Comments
 (0)