Ada*_*dam 2 firebase google-cloud-firestore
我对Firestore(和编程)比较陌生,无法在线解决我的问题。
寻找查询现有集合中的文档。所有文档都有一个时间戳字段。
当我尝试立即查询所有文档“>”或“ <”时,查询工作正常。7天前,当我尝试查询“>”或“ <”时,查询不返回任何内容。我确定我可能只是想念一些小东西。谢谢你的帮助!
这些退货文件符合预期:
var today = new Date();
db.collection("****").where('display', '==', true).where('createdAt', '>', today).get().then(function(querySnapshot) {
Run Code Online (Sandbox Code Playgroud)
和
var today = new Date();
db.collection("****").where('display', '==', true).where('createdAt', '<', today).get().then(function(querySnapshot) {
Run Code Online (Sandbox Code Playgroud)
这些不返回任何内容:
var today = new Date()-604800000;
db.collection("****").where('display', '==', true).where('createdAt', '>', today).get().then(function(querySnapshot) {
Run Code Online (Sandbox Code Playgroud)
和
var today = new Date();
db.collection("****").where('display', '==', true).where('createdAt', '>', today-604800000).get().then(function(querySnapshot) {
Run Code Online (Sandbox Code Playgroud)
只是为了它
var today = new Date()-1;
db.collection("****").where('display', '==', true).where('createdAt', '>', today).get().then(function(querySnapshot) {
Run Code Online (Sandbox Code Playgroud)
我见过其他人要求查看Firestore中的字段的外观,所以这是一张图片: 抱歉,这是一个链接
请让我知道是否还有其他可能有用的信息。谢谢!
编辑以显示下一个尝试:
var config = {****};
firebase.initializeApp(config);
const db = firebase.firestore();
const settings = {/* your settings... */ timestampsInSnapshots: true};
db.settings(settings);
var today = new Date();
var yesterday = date.setDate(today.getDate() - 1);
db.collection("****")
.where('display', '==', true)
.where('createdAt', '>', yesterday)
.get()
.then(function(querySnapshot) {console.log(createdAt)});
Run Code Online (Sandbox Code Playgroud)
Ada*_*dam 11
好。因此,我从一位很有帮助的Google开发人员那里得到了一些帮助。
最终成功了。
var beginningDate = Date.now() - 604800000;
var beginningDateObject = new Date(beginningDate);
db.collection("****")
.where('display', '==', true)
.where('createdAt', '>', beginningDateObject)
.get()
.then(function(querySnapshot) {console.log(/* ... */)});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4129 次 |
| 最近记录: |