본문 바로가기
반응형

mongodb26

[MongoDB] Create관련, 차이점 db.collection.insertOne(), db.collection.insertMany(), db.collection.bulkWrite() Create관련 MongoDB: db.collection.insert(): 지원중지, db.collection.save(): 지원중지, db.collection.insertOne(), db.collection.insertMany(), db.collection.bulkWrite() 1. db.collection.insertOne() InsertOne은 컬렉션에 단일 문서를 삽입하기 위해 삽입 명령을 실행한다. 문서 매개변수는 삽입할 문서여야 하고 0일 수 없다. 문서가 BSON으로 변환될 때 _id 필드가 없으면 마샬링된 문서에 자동으로 추가된다. (원본 문서는 .. 2023. 2. 27.
[MongoDB] Read관련, 차이점 [MongoDB] db.collection.find() vs db.collection.findOne() Read관련 MongoDB: db.collection.find(), db.collection.findOne() db.collection.find() vs db.collection.findOne() db.collection.find(): 컬렉션 또는 뷰에 대해 쿼리를 수행하고 쿼리에 해당하는 커서 개체를 반환한다. db.collection.findOne(): 쿼리를 수행하고 쿼리에 해당하는 하나의(최초의) 문서를 반환한다. 차이점: 문서를 반환한다는 기준으로 보면 쿼리에 해당하는 모든 문서를 찾는지 단일 문서를 찾는지에 대한 차이가 있다. 2023. 2. 26.
[MongoDB] CRUD 관련 모음(Bulk포함) [MongoDB] Create(생성), Read(조회), Update(변경), Delete(삭제)_Bulk포함 1. Create(생성) db.collection.insertOne(), db.collection.insertMany(), db.collection.bulkWrite(), Bulk.insert() 2. Read(조회) db.collection.find(), db.collection.findOne(), Bulk.find() 3. Update(변경) db.collection.findOneAndUpdate(), db.collection.updateOne(), db.collection.updateMany(), db.collection.findOneAndReplace(), db.collection.rep.. 2023. 2. 25.
[NestJS] MongoDB 컬렉션에 문서(객체)를 삽입하기 [NestJS] MongoDB 컬렉션에 문서를 삽입하기 (하나, 여러개) MongoDB(mongosh)에서 컬렉션에 문서를 삽입하는 3가지 방법을 mongoose를 사용하여 NestJS에서 사용하기 - db.collection.insert(): 하나 혹은 여러개의 문서를 삽입한다. - db.collection.insertOne(): 하나의 문서를 삽입한다. - db.collection.insertMany(): 여러개의 문서를 삽입한다. 1. 하나의 객체(문서) 생성(db.collection.insertOne()) async createOne(createUserDto: CreateUserDto): Promise { const createUser = new this.model(createUserDto); r.. 2023. 2. 21.
[MongoDB] 데이터 추출(페이지네이션), skip(), hasNext(), next() MongoDB 데이터 추출(페이지네이션 방식)할 때, 주의해야 할 점 MongoDB에서 페이지네이션 방식으로 데이터 추출할 때 2가지 방법이 있다. 1. skip()을 사용하는 방식 2. cursor.hasNext(), next()를 사용하는 방식 예제 코드) const page1 = db.items.find().limit(100) const page2_1 = db.items.find().skip(100).limit(100) let latest = null while(page1.hasNext()){ latest = page1.next() } const page2_2 = db.items .find({"date" : {"$gt" : latest.date}}) .limit(100) - page1이 첫번째 10.. 2023. 2. 20.
[MongoDB] Naver Cloud에서 MongoDB 데이터베이스 생성 Naver Cloud(NCloud)에서 MongoDB 데이터베이스 서버 생성 1. 네이버 클라우드 접속(https://www.ncloud.com/) 후 로그인 2. 우측 상단 콘솔버튼 클릭 3. 좌측 Services 클릭 4. Cloud DB for MongoDB 검색 5. DB Server 클릭 6. DB Server 생성 7. 상황에 맞게 클러스터, 서버, DB 설정 후 완료 2023. 2. 15.
반응형