반응형
몽고디비의 도큐먼트 하나는 자바스크립트 오브젝트이고
자바스크립트 오브젝트는 제이슨 오브젝트이다.
자바스크립트 오브젝트 모양은 {id:1, username:"ssar"} 이지만
{"id":1, "username":"ssar"}도 지원한다.
use("blog");
const user = {
"id":1,
"username":"ssar"
}
db.users.insertOne(user);
use("blog");
const userList = [
{id:5, username:"hello"},
{id:6, username:"jojo"},
{id:7, password:"1234"}
]
db.users.insertMany(userList);
검색도 제이슨으로 한다
use("blog");
db.users.find({username:"ssar"});
use("blog");
// db.createCollection("posts");
const post = {
id: 1,
title: "제목1",
content: "내용1",
user: {
id: 1,
username: "ssar",
email: "ssar@nate.com"
}
}
db.posts.insertOne(post);
// const userList = [
// {id:5, username:"hello"},
// {id:6, username:"jojo"},
// {id:7, password:"1234"}
// ]
// db.users.insertMany(userList);
// const user = {
// "id":4,
// "username":"cos"
// }
// db.users.insertOne(user);
// db.users.find({username:"ssar"});
[출처]
https://cafe.naver.com/metacoding
메타 코딩 유튜브
https://www.youtube.com/c/%EB%A9%94%ED%83%80%EC%BD%94%EB%94%A9
반응형