Firestore에서 Map 객체의 필드에 대해 Where 검색
소개
다음과 같이 Map 객체가 있는 컬렉션에 대해 Where 절에서 조건을 지정하여 데이터를 가져오는 메모입니다.
자신용 비망록을 겸한다. (오히려 그쪽의 목적이 크다)


검색 방법
where('[フィールド名].[Mapオブジェクト内のフィールド名]' , '==' , 'hogehoge')
와 같이 지정한다.
위의 예라면 where('data.name','==','hogehoge')
로 한다.
아래 Node.js 샘플
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
const hogehoge = db.collection('Hogehoge');
async function getHogehoge() {
try {
const querySnapShot = await hogehoge.where('data.name' , '==' , 'hogehoge').get(); // ここで条件指定する
var datas = [];
querySnapShot.forEach(async (d)=>{
datas.push(await d.data());
});
return datas;
} catch(err) {
throw err;
}
}
module.exports = {
getHogehoge: getHogehoge,
};
연산자 ==
의 부분은 공식 문서에 실려 있는 다른 연산자도 이용 가능.
htps : // 푹 빠져라. 오, ぇ. 코 m / 드 cs / 푹신 s 잡아 / 쿠에 ry-data / 쿠에 리 s? hl = 그럼 # 쿠에 ry_ 오페라와 rs
위의 문서에는 Map 객체에 대한 Where의 지정이 명기되어 있지 않은 것처럼 보였으므로 일단 자신을 위해 메모로 흥했다.
FieldPath를 사용하는 방법
where('data.name')
와 같이, where 메소드내의 필드명 부분에 닷을 써 직접 기술해도 동작하지만, FiledPath
를 사용하는 방법도 있다.
const { firestore } = require('firebase-admin');
...
const querySnapShot = await hogehoge.where(new firestore.FieldPath('data' , 'name') , '==' , 'hogehoge');
new firestore.FieldPath('data' , 'name')
가 where('data.name')
와 같은 일을 한다.
공식 문서는 이쪽↓
htps : // 푹 빠져라. 오, ぇ. 코 m/도 cs/레후오렌세/js/후우레바세. 푹신한 s. 푸에 ld 파 th? hl = 그럼
Reference
이 문제에 관하여(Firestore에서 Map 객체의 필드에 대해 Where 검색), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/ricemountainer/items/c276bc27331e08db4162
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
where('[フィールド名].[Mapオブジェクト内のフィールド名]' , '==' , 'hogehoge')
와 같이 지정한다.위의 예라면
where('data.name','==','hogehoge')
로 한다.아래 Node.js 샘플
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
const hogehoge = db.collection('Hogehoge');
async function getHogehoge() {
try {
const querySnapShot = await hogehoge.where('data.name' , '==' , 'hogehoge').get(); // ここで条件指定する
var datas = [];
querySnapShot.forEach(async (d)=>{
datas.push(await d.data());
});
return datas;
} catch(err) {
throw err;
}
}
module.exports = {
getHogehoge: getHogehoge,
};
연산자
==
의 부분은 공식 문서에 실려 있는 다른 연산자도 이용 가능.htps : // 푹 빠져라. 오, ぇ. 코 m / 드 cs / 푹신 s 잡아 / 쿠에 ry-data / 쿠에 리 s? hl = 그럼 # 쿠에 ry_ 오페라와 rs
위의 문서에는 Map 객체에 대한 Where의 지정이 명기되어 있지 않은 것처럼 보였으므로 일단 자신을 위해 메모로 흥했다.
FieldPath를 사용하는 방법
where('data.name')
와 같이, where 메소드내의 필드명 부분에 닷을 써 직접 기술해도 동작하지만, FiledPath
를 사용하는 방법도 있다.
const { firestore } = require('firebase-admin');
...
const querySnapShot = await hogehoge.where(new firestore.FieldPath('data' , 'name') , '==' , 'hogehoge');
new firestore.FieldPath('data' , 'name')
가 where('data.name')
와 같은 일을 한다.
공식 문서는 이쪽↓
htps : // 푹 빠져라. 오, ぇ. 코 m/도 cs/레후오렌세/js/후우레바세. 푹신한 s. 푸에 ld 파 th? hl = 그럼
Reference
이 문제에 관하여(Firestore에서 Map 객체의 필드에 대해 Where 검색), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/ricemountainer/items/c276bc27331e08db4162
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
const { firestore } = require('firebase-admin');
...
const querySnapShot = await hogehoge.where(new firestore.FieldPath('data' , 'name') , '==' , 'hogehoge');
Reference
이 문제에 관하여(Firestore에서 Map 객체의 필드에 대해 Where 검색), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ricemountainer/items/c276bc27331e08db4162텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)