저는 Firebase를 사용하여 사용자의 일부 데이터를 검색하고 있습니다. 사용자 (gameSearching = true
) 한 명만 검색해야합니다. 이 코드를 실행하는거야파이어베이스가 인덱스가 정의되지 않았습니다.
Users
|
|_____ John
| |___ name: John Farmer
| |___ gameSearching: true
|
|_____ James
| |___ name: James Smith
| |___ gameSearching: false
|
|_____ Barbara
|___ name: Barbara Smith
|___ gameSearching: true
: 같은
내 데이터가 보인다 '데이터'여러 값을 가지고 있기 때문에
이setData(('Users/' + you + '/'), {gameSearching: true});
var ref = new Firebase("https://grootproject.firebaseio.com/Users");
var child = ref.orderByChild("gameSearching");
child.on("child_added", function (data) {
var yourself = firebase.getAuth().password.email.split("@", 1)[0];
data.forEach(
function (childSnapshot) {
if (childSnapshot[i].val().gameSearching == true && childSnapshot[i].key() != yourself) {
var opponent = childSnapshot[i].key();
setData(('Users/' + opponent + '/'), {gameSearching: false});
setData(('Users/' + yourself + '/'), {gameSearching: false});
}
}
);
});
, 내가 그들을 분리하는 'data.forEach'를 사용합니다. 그 시점 이후에 나는 'true'에 'return'을 설정할 수 있으므로 'gameSearching : true'로 한 명의 사용자 만 수신합니다.
내 중포 기지 규칙 :
{
"rules": {
".read": true,
".write": true,
".indexOn": "gameSearching"
}
}
나는 다음과 같은 오류 얻을이 코드를 실행하면 :
'Uncaught Error: No index defined for gameSearching'
내가 'gameSearching'에 인덱스를 설정 검색 한 '.indexOn'를 사용을하지만, 어떤 succes도 아닙니다. https://www.firebase.com/docs/security/guide/indexing-data.html
누구나 예제가 있습니까?
편집 :
이제 다음과 같은 코드를 가지고:
{
"rules": {
".read": true,
".write": true,
"Users": {
".indexOn": "gameSearching"
}
}
}
indexOn 오류 :
var ref = new Firebase("https://grootproject.firebaseio.com/Users");
ref.orderByChild("gameSearching").equalTo(true).limitToFirst(1).on("child_added", function (data) {
var yourself = firebase.getAuth().password.email.split("@", 1)[0];
var opponent = data.key();
console.log(opponent);
setData(('Users/' + opponent + '/'), {gameSearching: false});
setData(('Users/' + yourself + '/'), {gameSearching: false});
console.log('ja');
});
내가 내 중포 기지 내 규칙을 편집을 더 이상 보여주지 않을 것이다. 훌륭합니다. 그러나
ref.orderByChild("gameSearching").equalTo(true).limitToFirst(1
)는 두 번 실행됩니다. 나는 그게 가능하다는 것을 모른다. 나는 limitToFirst (1)`을 사용하고 있습니다. 그래서 1 명의 자식을 기대합니까?
"어떤 문제도 없다"는 것은 무엇을 의미합니까? 나는 많은 인덱스를 추가했으며 항상 문제없이 작동합니다. 규칙의 관련 섹션을 보여줄 수 있습니까? (질문 아래에있는 편집 링크를 클릭하여 정보를 추가하십시오 ** 주석에 넣지 마십시오 **) –
명령은 위에서 입력 한 것처럼'.indexOf'가 아니라'.indexOn'입니다. 규칙에서 동일한 오타를 만든 경우 실제로 작동하지 않습니다. –
.indexOn, 죄송합니다. 내가 가진 문제는 .indexOn을 어디에 둘지 모르겠다는 것입니다. –