Firebase查询startAt总是返回至少一项

时间:2019-05-11 06:11:28

标签: javascript firebase firebase-realtime-database

对于firebase startAt()查询的行为,我有些困惑。 我正在尝试过滤例程运行后插入的所有项目。为此,我将系统时间保留在createdAt字段中。 我要实现的是在当前系统时间之后创建所有项目。 实际上,即使过去创建的数据集的最后一条记录也始终会返回。 这是一个片段:

let now = getServerTime(Firebase.database().ref('/'))();

listener_added = Firebase.database().ref(url)
    .orderByChild('createdAt').startAt(now)
    .on('child_added', snapshot => {....

只要我不向表中添加任何新行,它就不会返回任何内容。 它错误地返回了数据集中的createdAt时间戳低于“ now”变量的最后一行。事实上,仅返回最后(及时)行,其他所有行均被跳过。

这是一个json代码段:

   {
  "-LffdRyzER4ZH9HGJYcs" : {
    "autore" : "Mauro Minenna",
    "changedAt" : 1558676888318,
    "changedBy" : "AGdyklHWhjfNk7wYYh1tPmxss573",
    "cliente" : "-Layy4mzKi1RzW3P_-2A",
    "createdAt" : 1558676876634,
    "createdBy" : "AGdyklHWhjfNk7wYYh1tPmxss573",
    "dataOrdine" : 1556964000000,
    "ean" : "2000000000046",
    "editore" : "Cologno",
    "history" : {
      "-LfcNPniyo0kyzO4qOtP" : {
        "at" : 1558676876634,
        "source" : "user",
        "stato" : "D"
      },
      "-LfcNSeKMRRaiokup_YF" : {
        "at" : 1558676888318,
        "source" : "user",
        "stato" : "O"
      },
      "-LffacR-OYIrM3brQHsy" : {
        "at" : 1558730934167,
        "path" : "bolla/2019/01/-LVwVrAzOPZGTvhrpSiN",
        "source" : "clone",
        "stato" : "O"
      },
      "-LffdRyypntuZuqiNlPb" : {
        "at" : 1558731673702,
        "path" : "bolla/2019/05/-Lffcnwdy7U6HSnPYzLR",
        "source" : "clone",
        "stato" : "O"
      },
      "-Lfjvcez3vouQYlWQHUM" : {
        "at" : 1558803549013,
        "path" : "bolla/2019/05/-Lffcnwdy7U6HSnPYzLR",
        "source" : "bolla",
        "stato" : "R"
      }
    },
    "imgFirebaseUrl" : "",
    "imgUrl" : "",
    "manSconto" : false,
    "ordine" : "-Ldzmvb8TSu8cGFwRJVl",
    "pezzi" : 1,
    "prezzoListino" : "11.00",
    "prezzoTotale" : "11.00",
    "prezzoUnitario" : "11.00",
    "sconto" : 0,
    "stato" : "R",
    "titolo" : "Una prova"
  },
  "-Lfjqw-ukiL6NYRO3sug" : {
    "autore" : "Alessandro Manzoni",
    "categoria" : "-LL59jknmY4v2PEDvPn3",
    "cliente" : "-Lb2sFXsqfKciliy0F0f",
    "createdAt" : 1558802317515,
    "createdBy" : "AGdyklHWhjfNk7wYYh1tPmxss573",
    "dataOrdine" : 1556791200000,
    "ean" : "2000000000015",
    "editore" : "Einaudi",
    "history" : {
      "-Lfjqd7_DbQ1ypU0mJkW" : {
        "at" : 1558802317515,
        "source" : "user",
        "stato" : "D"
      },
      "-Lfjqw-rRJkOoP7C-CGh" : {
        "at" : 1558802317515,
        "source" : "user",
        "stato" : "D"
      },
      "-LfjwW1C05Dj0FAsAcV0" : {
        "at" : 1558803779872,
        "path" : "bolla/2019/05/-Lffcnwdy7U6HSnPYzLR",
        "source" : "bolla",
        "stato" : "R"
      }
    },
    "imgFirebaseUrl" : "https://firebasestorage.googleapis.com/v0/b/brucabook.appspot.com/o/images%2Fbooks%2F-L0Lp-qQXGuhOi9ioFQU%2F-L0TzOM2HoQXDNA8_9sA%2F2000000000015.jpg?alt=media&token=3787cd81-0910-44c9-968b-5f693bc9d219",
    "imgUrl" : "",
    "iva" : "a0",
    "manSconto" : false,
    "nomeCategoria" : "Saggi",
    "ordine" : "-LduC3Hov8v3XN5Dm6I9",
    "pezzi" : 1,
    "prezzoListino" : "12.90",
    "prezzoTotale" : "12.90",
    "prezzoUnitario" : "12.90",
    "sconto" : 0,
    "stato" : "R",
    "titolo" : "I Promessi Sposi"
  },
  "-LfjzTsSbfiaTxs_Hkiy" : {
    "autore" : "Matilde Minenna",
    "cliente" : "-Layy4mzKi1RzW3P_-2A",
    "createdAt" : 1558804557497,
    "createdBy" : "AGdyklHWhjfNk7wYYh1tPmxss573",
    "dataOrdine" : 1556964000000,
    "ean" : "2000000000039",
    "editore" : "Cagnotto",
    "history" : {
      "-LfjzTsRg0TYFdLlI8SB" : {
        "at" : 1558804557497,
        "source" : "user",
        "stato" : "D"
      },
      "-LfjzYuNWMxidgK1WnFr" : {
        "at" : 1558804578109,
        "path" : "bolla/2019/05/-Lffcnwdy7U6HSnPYzLR",
        "source" : "bolla",
        "stato" : "R"
      }
    },
    "imgFirebaseUrl" : "",
    "imgUrl" : "",
    "manSconto" : false,
    "ordine" : "-Ldzmvb8TSu8cGFwRJVl",
    "pezzi" : 1,
    "prezzoListino" : "17.50",
    "prezzoTotale" : "17.50",
    "prezzoUnitario" : "17.50",
    "sconto" : 0,
    "stato" : "R",
    "titolo" : "La fuga del cavallo morto"
  },
  "-LfjzYuNWMxidgK1WnFq" : {
    "autore" : "Matilde Minenna",
    "cliente" : "-Layy4mzKi1RzW3P_-2A",
    "createdAt" : 1558804557497,
    "createdBy" : "AGdyklHWhjfNk7wYYh1tPmxss573",
    "dataOrdine" : 1556964000000,
    "ean" : "2000000000039",
    "editore" : "Cagnotto",
    "history" : {
      "-LfjzTsRg0TYFdLlI8SB" : {
        "at" : 1558804557497,
        "source" : "user",
        "stato" : "D"
      },
      "-LfjzYuNWMxidgK1WnFp" : {
        "at" : 1558804578109,
        "path" : "bolla/2019/05/-Lffcnwdy7U6HSnPYzLR",
        "source" : "clone",
        "stato" : "D"
      },
      "-Lfk7pZ2VbvVEq68J2EL" : {
        "at" : 1558807009115,
        "path" : "bolla/2019/05/-Lffcnwdy7U6HSnPYzLR",
        "source" : "bolla",
        "stato" : "R"
      }
    },
    "imgFirebaseUrl" : "",
    "imgUrl" : "",
    "manSconto" : false,
    "ordine" : "-Ldzmvb8TSu8cGFwRJVl",
    "pezzi" : 1,
    "prezzoListino" : "17.50",
    "prezzoTotale" : "17.50",
    "prezzoUnitario" : "17.50",
    "sconto" : 0,
    "stato" : "R",
    "titolo" : "La fuga del cavallo morto"
  },
  "-Lfk3vXzlHXwV4MXrnRY" : {
    "autore" : "Collodi",
    "categoria" : "-LL59iB3onWyGUb2JCZD",
    "cliente" : "-Layy4mzKi1RzW3P_-2A",
    "createdAt" : 1558805985616,
    "createdBy" : "AGdyklHWhjfNk7wYYh1tPmxss573",
    "dataOrdine" : 1556964000000,
    "ean" : "2000000000022",
    "editore" : "Mondadori ",
    "history" : {
      "-Lfk3vXxn6_OwIabaUkQ" : {
        "at" : 1558805985616,
        "source" : "user",
        "stato" : "D"
      }
    },
    "imgFirebaseUrl" : "https://firebasestorage.googleapis.com/v0/b/brucabook.appspot.com/o/images%2Fbooks%2F-L0Lp-qQXGuhOi9ioFQU%2F-L0TzOM2HoQXDNA8_9sA%2F2000000000022.jpg?alt=media&token=5f5a91a6-4a14-44c0-b7d7-d996936ce72e",
    "imgFullName" : "images/books/-L0Lp-qQXGuhOi9ioFQU/-L0TzOM2HoQXDNA8_9sA/2000000000022.jpg",
    "imgUrl" : "",
    "iva" : "a0",
    "manSconto" : false,
    "nomeCategoria" : "Gialli",
    "ordine" : "-Ldzmvb8TSu8cGFwRJVl",
    "pezzi" : 1,
    "prezzoListino" : "13.50",
    "prezzoTotale" : "13.50",
    "prezzoUnitario" : "13.50",
    "sconto" : 0,
    "stato" : "D",
    "titolo" : "Pinocchio"
  },
  "-Lfk7pZ2VbvVEq68J2EK" : {
    "autore" : "Matilde Minenna",
    "cliente" : "-Layy4mzKi1RzW3P_-2A",
    "createdAt" : 1558804557497,
    "createdBy" : "AGdyklHWhjfNk7wYYh1tPmxss573",
    "dataOrdine" : 1556964000000,
    "ean" : "2000000000039",
    "editore" : "Cagnotto",
    "history" : {
      "-LfjzTsRg0TYFdLlI8SB" : {
        "at" : 1558804557497,
        "source" : "user",
        "stato" : "D"
      },
      "-LfjzYuNWMxidgK1WnFp" : {
        "at" : 1558804578109,
        "path" : "bolla/2019/05/-Lffcnwdy7U6HSnPYzLR",
        "source" : "clone",
        "stato" : "D"
      },
      "-Lfk7pZ2VbvVEq68J2EJ" : {
        "at" : 1558807009115,
        "path" : "bolla/2019/05/-Lffcnwdy7U6HSnPYzLR",
        "source" : "clone",
        "stato" : "D"
      }
    },
    "imgFirebaseUrl" : "",
    "imgUrl" : "",
    "manSconto" : false,
    "ordine" : "-Ldzmvb8TSu8cGFwRJVl",
    "pezzi" : 1,
    "prezzoListino" : "17.50",
    "prezzoTotale" : "17.50",
    "prezzoUnitario" : "17.50",
    "sconto" : 0,
    "stato" : "D",
    "titolo" : "La fuga del cavallo morto"
  }
}

0 个答案:

没有答案