-
글쓴이글
-
2023년 2월 8일 20:05 #67453
codingapple키 마스터forEach 는 아직 있군요 forEach 전부 지우고 console.log(result.empty) 하면 중복일 때 중복 아닐 때 각각 무엇이 나옵니까
2023년 2월 9일 01:28 #67509
이형민참가자$('#chat').click(function () { db.collection("chatroom").where("who", "array-contains-any", [내uid, 판매자uid]).get().then((result) => { console.log(result.empty) }) }) 선생님 말씀대로 코드 위처럼 작성해서 확인해보니 중복일 때 아닐 때 모두 false로 출력됩니다. 어떻게 해야할까요?
2023년 2월 9일 09:54 #67545
codingapple키 마스터내uid, 판매자uid 출력해서 잘 나오는지 확인하고 DB에 내uid, 판매자uid 둘다 들어있는 document들이 실제로 있나 확인합시다
2023년 2월 10일 16:25 #67813
이형민참가자$('#chat').click(function () {
db.collection("chatroom").where("who", "array-contains-any", [구매자uid, 판매자uid]).get().then((result) => { console.log(result.empty) console.log(구매자uid) console.log(판매자uid)
// if (result.empty) { // //채팅방 id 출력 // db.collection("chatroom").get(a.id).then(function (doc) { // console.log(a.id) // }); // 기존채팅방id = a.id; // console.log(기존채팅방id); // //기존 채팅방으로 가기 // setTimeout(() => window.location.href = 'chatroom.html?id=' + 기존채팅방id, 2000); // } // else { // var 데이터 = { // who: [내uid, 판매자uid], // 판매자uid, // product: 상품명, // date: new Date() // } // db.collection('chatroom').add(데이터).then(function (doc) { // console.log(doc.id); // sessionStorage.setItem('chatroom', JSON.stringify(doc.id))
// 채팅방id = JSON.parse(sessionStorage.getItem('chatroom'));
// setTimeout(() => window.location.href = 'chatroom.html?id=' + 채팅방id, 2000); // }) // } }) }) 현재 위와 같이 코드를 작성하여 확인해본 결과, 중복이든 아니든 false를 출력하고 있으며, db 상에는 구매자uid와 판매자uid가 실제로 존재하고 있습니다. 리럴 때는 뭐가 문제인가요..
2023년 2월 10일 20:33 #67862
codingapple키 마스터콘솔창에 uid출력시 이상한 공백같은건 없나 확인합시다 chatroom collection에 저장된 uid들도 공백있나 확인합시다
2023년 2월 11일 02:51 #67902
이형민참가자말씀하신 공백은 없어서 여러가지 시도해본 결과
$('#chat').click(function () { db.collection("chatroom").where("who", "array-contains-any", [구매자uid, 판매자uid]).get(쿼리스트링.get('id')).then((result) => { console.log(result.empty) console.log(구매자uid) console.log(판매자uid) if (result.empty == true) { //새로 채팅방 개설 var 데이터 = { who: [내uid, 판매자uid], 판매자uid, product: 상품명, productID, date: new Date() } db.collection('chatroom').add(데이터).then(function (doc) { console.log(doc.id); sessionStorage.setItem('chatroom', JSON.stringify(doc.id))
채팅방id = JSON.parse(sessionStorage.getItem('chatroom'));
setTimeout(() => window.location.href = 'chatroom.html?id=' + 채팅방id, 2000); }) } else { //기존 채팅방 불러오기 } }) }) 이러한 식으로 채팅방을 짜봤는데요, 문제는 db 상에 chatroom collection 내에 어떠한 데이터도 저장된 것이 없을 때에는 result.empy를 콘솔에 띄웠을 떄에 true를 출력시키는 반면에 정보가 들어있을 때에는 false를 출력시킵니다. #chat을 눌렀을 때의 detail 페이지에 해당하는 채팅방과 동일한 채팅방이 존재하지 않을 때에는 result.empty가 true를 출력하게 하려면 어떻게 코드를 짜야할까요?
-
글쓴이글
- 답변은 로그인 후 가능합니다.