Node.js 需要帮助解决firebase查询吗
我的节点后端已连接到Firestore。我需要执行与MySQL等价的查询:Node.js 需要帮助解决firebase查询吗,node.js,firebase,google-cloud-firestore,Node.js,Firebase,Google Cloud Firestore,我的节点后端已连接到Firestore。我需要执行与MySQL等价的查询: SELECT * FROM offer WHERE zip = '..' AND category = '...' AND status != 1 ORDER BY .. 到目前为止,我尝试了以下Firebase查询: const docRef = db.collection('ads'); await docRef.where('status', '<', 4).where('status', '>',
SELECT * FROM offer WHERE zip = '..' AND category = '...' AND status != 1 ORDER BY ..
到目前为止,我尝试了以下Firebase查询:
const docRef = db.collection('ads');
await docRef.where('status', '<', 4).where('status', '>', 5).orderBy('status')
.where('zip', '==', searchTerm).where('subCategory', '==', subCategory).orderBy('createdAt')
const docRef=db.collection('ads');
等待docRef.where('status','',5).orderBy('status'))
.where('zip','==',searchTerm)。where('subCategory','==',subCategory)。orderBy('createdAt'))
此查询返回空数组。我对Firebase相当陌生。首先,一个(来自db.collection(…)
)应该命名为colRef
或类似名称。虽然与a类似,但它们的工作方式不同,含义也不同
这一行定义的查询表示“查找状态必须小于4且大于5的文档,并按其状态值对其进行排序”
这假设状态永远不小于1。如果是,您还需要第二个单独的查询:
colRef.where('status', '<', 1).orderBy('status')
.where('zip', '==', searchTerm).where('subCategory', '==', subCategory).orderBy('createdAt')
colRef.where('status',您的查询正在检查状态小于4且大于5。基于您的MySQL查询,我认为您需要where('status',!=',1)
@jmalenfant Firebase没有可在where(…)中使用的不等式('
或'!='
)
@samthecodingman很奇怪。他可以使用.query()
然后使用SQL,对吗?为了保持Firestore查询的性能,这些查询不受支持。请查看。
colRef.where('status', '>', 1).orderBy('status')
.where('zip', '==', searchTerm).where('subCategory', '==', subCategory).orderBy('createdAt');
colRef.where('status', '<', 1).orderBy('status')
.where('zip', '==', searchTerm).where('subCategory', '==', subCategory).orderBy('createdAt')